commit 6e5b3bd: [Minor] Detect logger's debug level in lua debug utilities
Vsevolod Stakhov
vsevolod at highsecure.ru
Tue Aug 24 09:49:05 UTC 2021
Author: Vsevolod Stakhov
Date: 2021-08-24 10:45:38 +0100
URL: https://github.com/rspamd/rspamd/commit/6e5b3bd6f946073d0bd15885170b920dc9394bc2 (HEAD -> master)
[Minor] Detect logger's debug level in lua debug utilities
---
lualib/lua_util.lua | 25 ++++++++++++-------------
src/libserver/logger.h | 2 ++
src/lua/lua_logger.c | 18 ++++++++++++++++++
3 files changed, 32 insertions(+), 13 deletions(-)
diff --git a/lualib/lua_util.lua b/lualib/lua_util.lua
index 929488929..c4a925ed8 100644
--- a/lualib/lua_util.lua
+++ b/lualib/lua_util.lua
@@ -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
diff --git a/src/libserver/logger.h b/src/libserver/logger.h
index 9f90fbffa..18662d31d 100644
--- a/src/libserver/logger.h
+++ b/src/libserver/logger.h
@@ -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
diff --git a/src/lua/lua_logger.c b/src/lua/lua_logger.c
index 17705947b..0f015f70a 100644
--- a/src/lua/lua_logger.c
+++ b/src/lua/lua_logger.c
@@ -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
More information about the Commits
mailing list