diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-08-10 18:09:44 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-08-10 18:09:44 +0100 |
commit | cd994934d1f2bfd7ca484a5588c1d9911f140c35 (patch) | |
tree | 5dc5e4f412587fa0906f43ad6790f243e4972b7c /lualib | |
parent | 5a3a2f5427bc838b3fc07762b191f81b5b43eca6 (diff) | |
download | rspamd-cd994934d1f2bfd7ca484a5588c1d9911f140c35.tar.gz rspamd-cd994934d1f2bfd7ca484a5588c1d9911f140c35.zip |
[Feature] Add pure Lua debugm function
Diffstat (limited to 'lualib')
-rw-r--r-- | lualib/lua_util.lua | 33 |
1 files changed, 33 insertions, 0 deletions
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 |