commit a72937f: [Minor] Lua_util: Implement debug aliases

Vsevolod Stakhov vsevolod at highsecure.ru
Mon Dec 31 12:07:06 UTC 2018


Author: Vsevolod Stakhov
Date: 2018-12-31 11:31:16 +0000
URL: https://github.com/rspamd/rspamd/commit/a72937fcfbd01b7d47bde8a46f73d01812f13ce0

[Minor] Lua_util: Implement debug aliases

---
 lualib/lua_util.lua | 35 +++++++++++++++++++++++++++++++----
 1 file changed, 31 insertions(+), 4 deletions(-)

diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index 0d56e689d..b12a258f5 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -770,6 +770,7 @@ end
 -- Debugging support
 local unconditional_debug = false
 local debug_modules = {}
+local debug_aliases = {}
 local log_level = 384 -- debug + forced (1 << 7 | 1 << 8)
 
 if type(rspamd_config) == 'userdata' then
@@ -784,10 +785,22 @@ if type(rspamd_config) == 'userdata' then
       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)
+    if not unconditional_debug 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)
+        end
+      end
+
+      if #debug_aliases > 0 then
+        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)',
+                alias, mod)
+          end
+        end
       end
     end
   end
@@ -808,6 +821,20 @@ exports.debugm = function(mod, obj_or_fmt, fmt_or_something, ...)
   end
 end
 
+--[[[
+-- @function lua_util.add_debug_alias(mod, alias)
+-- Add debugging alias so logging to `alias` will be treated as logging to `mod`
+--]]
+exports.add_debug_alias = function(mod, alias)
+  local logger = require "rspamd_logger"
+  debug_aliases[alias] = mod
+
+  if debug_modules[mod] then
+    debug_modules[alias] = true
+    logger.infox(rspamd_config, 'enable debug for Lua module %s (%s aliased)',
+        alias, mod)
+  end
+end
 ---[[[
 -- @function lua_util.get_task_verdict(task)
 -- Returns verdict for a task, must be called from idempotent filters only


More information about the Commits mailing list