]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
[Minor] Detect logger's debug level in lua debug utilities
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 24 Aug 2021 09:45:38 +0000 (10:45 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Tue, 24 Aug 2021 09:45:38 +0000 (10:45 +0100)
lualib/lua_util.lua
src/libserver/logger.h
src/lua/lua_logger.c

index 9294889296b543bcd4333927b6e4b89dbf103150..c4a925ed8ebd4a87dfef6670bc0a09b677d083c9 100644 (file)
@@ -1051,27 +1051,26 @@ exports.shallowcopy = function(orig)
 end
 
 -- Debugging support
-local unconditional_debug = false
+local logger = require "rspamd_logger"
+local unconditional_debug = logger.log_level() == 'debug'
 local debug_modules = {}
 local debug_aliases = {}
 local log_level = 384 -- debug + forced (1 << 7 | 1 << 8)
 
 
 exports.init_debug_logging = function(config)
-  local logger = require "rspamd_logger"
   -- Fill debug modules from the config
-  local logging = 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
+  if not unconditional_debug then
+    local log_config = config:get_all_opt('logging')
+    if log_config then
+      local log_level_str = log_config.level
+      if log_level_str then
+        if log_level_str == 'debug' then
+          unconditional_debug = true
+        end
       end
-    end
-
-    if not unconditional_debug then
-      if logging.debug_modules then
-        for _,m in ipairs(logging.debug_modules) do
+      if log_config.debug_modules then
+        for _,m in ipairs(log_config.debug_modules) do
           debug_modules[m] = true
           logger.infox(config, 'enable debug for Lua module %s', m)
         end
index 9f90fbffa49cf39722172a37a1094b9631213897..18662d31dd85e8cf868f371bafdc9a82c9fc11f7 100644 (file)
@@ -89,6 +89,8 @@ rspamd_logger_t * rspamd_log_open_specific (rspamd_mempool_t *pool,
  * @param level
  */
 void rspamd_log_set_log_level (rspamd_logger_t *logger, gint level);
+gint rspamd_log_get_log_level (rspamd_logger_t *logger);
+const gchar *rspamd_get_log_severity_string(gint level_flags);
 /**
  * Set log flags (from enum rspamd_log_flags)
  * @param logger
index 17705947be50f6257fdb9b8198d9483731cc279d..0f015f70ad4e744eb038927b7ae071e879fa0237 100644 (file)
@@ -150,6 +150,13 @@ LUA_FUNCTION_DEF (logger, slog);
  */
 LUA_FUNCTION_DEF (logger, logx);
 
+/***
+ * @function logger.log_level()
+ * Returns log level for a logger
+ * @return {string} current log level
+ */
+LUA_FUNCTION_DEF (logger, log_level);
+
 static const struct luaL_reg loggerlib_f[] = {
                LUA_INTERFACE_DEF (logger, err),
                LUA_INTERFACE_DEF (logger, warn),
@@ -166,6 +173,7 @@ static const struct luaL_reg loggerlib_f[] = {
                LUA_INTERFACE_DEF (logger, debugm),
                LUA_INTERFACE_DEF (logger, slog),
                LUA_INTERFACE_DEF (logger, logx),
+               LUA_INTERFACE_DEF (logger, log_level),
                {"__tostring", rspamd_lua_class_tostring},
                {NULL, NULL}
 };
@@ -1055,6 +1063,16 @@ lua_logger_slog (lua_State *L)
        return lua_logger_do_log (L, 0, TRUE, 1);
 }
 
+static gint
+lua_logger_log_level (lua_State *L)
+{
+       gint log_level = rspamd_log_get_log_level (NULL);
+
+       lua_pushstring (L, rspamd_get_log_severity_string(log_level));
+
+       return 1;
+}
+
 /*** Init functions ***/
 
 static gint