From: Vsevolod Stakhov Date: Mon, 13 Aug 2018 14:04:42 +0000 (+0100) Subject: [Minor] Fix conditional debugging X-Git-Tag: 1.8.0~267 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4ba8e13af571398fbaa8877c999ee77fd39f39ac;p=rspamd.git [Minor] Fix conditional debugging --- diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index 64d949270..0ce0c1874 100644 --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@ -693,7 +693,7 @@ end exports.debugm = function(mod, ...) local logger = require "rspamd_logger" if unconditional_debug or debug_modules[mod] then - logger.logx(log_level, ...) + logger.logx(log_level, mod, ...) end end diff --git a/src/libutil/logger.c b/src/libutil/logger.c index c9f14ccb6..0e20ec8e0 100644 --- a/src/libutil/logger.c +++ b/src/libutil/logger.c @@ -655,7 +655,7 @@ rspamd_common_logv (rspamd_logger_t *rspamd_log, gint level_flags, const gchar *fmt, va_list args) { gchar logbuf[RSPAMD_LOGBUF_SIZE], *end; - gint level = level_flags & (RSPAMD_LOG_LEVEL_MASK & G_LOG_LEVEL_MASK); + gint level = level_flags & (RSPAMD_LOG_LEVEL_MASK & G_LOG_LEVEL_MASK), mod_id; if (G_UNLIKELY (rspamd_log == NULL)) { rspamd_log = default_logger; @@ -669,7 +669,14 @@ rspamd_common_logv (rspamd_logger_t *rspamd_log, gint level_flags, } } else { - if (rspamd_logger_need_log (rspamd_log, level, -1)) { + if (level == G_LOG_LEVEL_DEBUG) { + mod_id = rspamd_logger_add_debug_module (module); + } + else { + mod_id = -1; + } + + if (rspamd_logger_need_log (rspamd_log, level_flags, mod_id)) { end = rspamd_vsnprintf (logbuf, sizeof (logbuf), fmt, args); if ((level_flags & RSPAMD_LOG_ENCRYPTED) && rspamd_log->pk) { diff --git a/src/lua/lua_logger.c b/src/lua/lua_logger.c index fe2fe7d28..75c2984c6 100644 --- a/src/lua/lua_logger.c +++ b/src/lua/lua_logger.c @@ -141,7 +141,7 @@ LUA_FUNCTION_DEF (logger, debugm); LUA_FUNCTION_DEF (logger, slog); /*** - * @function logger.logx(level, id, fmt[, args) + * @function logger.logx(level, module, id, fmt[, args) * Extended interface to make a generic log message on any level * @param {number} log level as a number (see GLogLevelFlags enum for values) * @param {task|cfg|pool|string} id id to log @@ -804,8 +804,29 @@ lua_logger_logx (lua_State *L) { LUA_TRACE_POINT; GLogLevelFlags flags = lua_tonumber (L, 1); + const gchar *modname = lua_tostring (L, 2), *uid = NULL; + gchar logbuf[RSPAMD_LOGBUF_SIZE - 128]; + gboolean ret; + + if (lua_type (L, 3) == LUA_TSTRING) { + uid = luaL_checkstring (L, 3); + } + else { + uid = lua_logger_get_id (L, 3, NULL); + } - return lua_logger_do_log (L, flags, FALSE, 2); + if (uid && modname && lua_type (L, 4) == LUA_TSTRING) { + ret = lua_logger_log_format (L, 4, FALSE, logbuf, sizeof (logbuf) - 1); + + if (ret) { + lua_common_log_line (flags, L, logbuf, uid, modname); + } + } + else { + return luaL_error (L, "invalid arguments"); + } + + return 0; }