From cd994934d1f2bfd7ca484a5588c1d9911f140c35 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Fri, 10 Aug 2018 18:09:44 +0100 Subject: [Feature] Add pure Lua debugm function --- lualib/lua_util.lua | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'lualib') diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua index ba5843ff6..64d949270 100644 --- a/lualib/lua_util.lua +++ b/lualib/lua_util.lua @@ -664,4 +664,37 @@ exports.extract_specific_urls = function(params_or_task, lim, need_emails, filte return res end +-- Debugging support +local unconditional_debug = false +local debug_modules = {} +local log_level = 384 -- debug + forced (1 << 7 | 1 << 8) + +if type(rspamd_config) == 'userdata' then + local logger = require "rspamd_logger" + -- Fill debug modules from the config + local logging = rspamd_config:get_all_opt('logging') + if logging then + local log_level_str = logging.level + if log_level_str then + if log_level_str == 'debug' then + unconditional_debug = true + end + end + + if not unconditional_debug and 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) + end + end + end +end + +exports.debugm = function(mod, ...) + local logger = require "rspamd_logger" + if unconditional_debug or debug_modules[mod] then + logger.logx(log_level, ...) + end +end + return exports -- cgit v1.2.3