local debug_aliases = {}
local log_level = 384 -- debug + forced (1 << 7 | 1 << 8)
-if type(rspamd_config) == 'userdata' then
+
+exports.init_debug_logging = function(config)
local logger = require "rspamd_logger"
-- Fill debug modules from the config
- local logging = rspamd_config:get_all_opt('logging')
+ local logging = config:get_all_opt('logging')
if logging then
local log_level_str = logging.level
if log_level_str then
if logging.debug_modules then
for _,m in ipairs(logging.debug_modules) do
debug_modules[m] = true
- logger.infox(rspamd_config, 'enable debug for Lua module %s', m)
+ logger.infox(config, 'enable debug for Lua module %s', m)
end
end
for alias,mod in pairs(debug_aliases) do
if debug_modules[mod] then
debug_modules[alias] = true
- logger.infox(rspamd_config, 'enable debug for Lua module %s (%s aliased)',
+ logger.infox(config, 'enable debug for Lua module %s (%s aliased)',
alias, mod)
end
end
} else {
logger_fin (cfg->cfg_pool, logger_ud);
}
+
+ /* Init lua logging */
+ lua_State *L = cfg->lua_state;
+ gint err_idx;
+ struct rspamd_config **pcfg;
+
+ lua_pushcfunction (L, &rspamd_lua_traceback);
+ err_idx = lua_gettop (L);
+
+ /* Obtain function */
+ if (!rspamd_lua_require_function (L, "lua_util",
+ "init_debug_logging")) {
+ msg_err_config ("cannot require lua_util.init_debug_logging");
+ lua_settop (L, err_idx - 1);
+
+ return FALSE;
+ }
+
+ pcfg = lua_newuserdata (L, sizeof (*pcfg));
+ *pcfg = cfg;
+ rspamd_lua_setclass (L, "rspamd{config}", -1);
+
+ if (lua_pcall (L, 1, 0, err_idx) != 0) {
+ GString *tb;
+
+ tb = lua_touserdata (L, -1);
+ msg_err_config ("cannot call lua init_debug_logging script: %s",
+ tb->str);
+ g_string_free (tb, TRUE);
+ lua_settop (L, err_idx - 1);
+
+ return FALSE;
+ }
+
+ lua_settop (L, err_idx - 1);
}
HASH_DEL (top, logger_section);