aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2018-08-10 18:09:44 +0100
committerVsevolod Stakhov <vsevolod@highsecure.ru>2018-08-10 18:09:44 +0100
commitcd994934d1f2bfd7ca484a5588c1d9911f140c35 (patch)
tree5dc5e4f412587fa0906f43ad6790f243e4972b7c /src
parent5a3a2f5427bc838b3fc07762b191f81b5b43eca6 (diff)
downloadrspamd-cd994934d1f2bfd7ca484a5588c1d9911f140c35.tar.gz
rspamd-cd994934d1f2bfd7ca484a5588c1d9911f140c35.zip
[Feature] Add pure Lua debugm function
Diffstat (limited to 'src')
-rw-r--r--src/libutil/logger.c2
-rw-r--r--src/lua/lua_logger.c98
2 files changed, 56 insertions, 44 deletions
diff --git a/src/libutil/logger.c b/src/libutil/logger.c
index bbdc69e97..c9f14ccb6 100644
--- a/src/libutil/logger.c
+++ b/src/libutil/logger.c
@@ -545,7 +545,7 @@ rspamd_logger_need_log (rspamd_logger_t *rspamd_log, GLogLevelFlags log_level,
{
g_assert (rspamd_log != NULL);
- if (log_level <= rspamd_log->cfg->log_level) {
+ if ((log_level & RSPAMD_LOG_FORCED) || log_level <= rspamd_log->cfg->log_level) {
return TRUE;
}
diff --git a/src/lua/lua_logger.c b/src/lua/lua_logger.c
index 87a45c1d5..fe2fe7d28 100644
--- a/src/lua/lua_logger.c
+++ b/src/lua/lua_logger.c
@@ -195,44 +195,22 @@ lua_common_log_line (GLogLevelFlags level, lua_State *L,
d.currentline);
}
- if (level == G_LOG_LEVEL_DEBUG) {
- rspamd_conditional_debug (NULL,
- NULL,
- module,
- uid,
- func_buf,
- "%s",
- msg);
- }
- else {
- rspamd_common_log_function (NULL,
- level,
- module,
- uid,
- func_buf,
- "%s",
- msg);
- }
+ rspamd_common_log_function (NULL,
+ level,
+ module,
+ uid,
+ func_buf,
+ "%s",
+ msg);
}
else {
- if (level == G_LOG_LEVEL_DEBUG) {
- rspamd_conditional_debug (NULL,
- NULL,
- module,
- uid,
- G_STRFUNC,
- "%s",
- msg);
- }
- else {
- rspamd_common_log_function (NULL,
- level,
- module,
- uid,
- G_STRFUNC,
- "%s",
- msg);
- }
+ rspamd_common_log_function (NULL,
+ level,
+ module,
+ uid,
+ G_STRFUNC,
+ "%s",
+ msg);
}
}
@@ -516,7 +494,7 @@ lua_logger_out_type (lua_State *L, gint pos, gchar *outbuf, gsize len)
}
static const gchar *
-lua_logger_get_id (lua_State *L, gint pos)
+lua_logger_get_id (lua_State *L, gint pos, GError **err)
{
const gchar *uid = NULL, *clsname;
@@ -536,6 +514,10 @@ lua_logger_get_id (lua_State *L, gint pos)
if (task) {
uid = task->task_pool->tag.uid;
}
+ else {
+ g_set_error (err, g_quark_from_static_string ("lua_logger"),
+ EINVAL, "invalid rspamd{task}");
+ }
}
else if (strcmp (clsname, "rspamd{mempool}") == 0) {
rspamd_mempool_t *pool;
@@ -545,6 +527,10 @@ lua_logger_get_id (lua_State *L, gint pos)
if (pool) {
uid = pool->tag.uid;
}
+ else {
+ g_set_error (err, g_quark_from_static_string ("lua_logger"),
+ EINVAL, "invalid rspamd{mempool}");
+ }
}
else if (strcmp (clsname, "rspamd{config}") == 0) {
struct rspamd_config *cfg;
@@ -552,7 +538,13 @@ lua_logger_get_id (lua_State *L, gint pos)
cfg = lua_check_config (L, pos);
if (cfg) {
- uid = cfg->checksum;
+ if (cfg->checksum) {
+ uid = cfg->checksum;
+ }
+ }
+ else {
+ g_set_error (err, g_quark_from_static_string ("lua_logger"),
+ EINVAL, "invalid rspamd{config}");
}
}
else if (strcmp (clsname, "rspamd{map}") == 0) {
@@ -568,12 +560,24 @@ lua_logger_get_id (lua_State *L, gint pos)
uid = "embedded";
}
}
+ else {
+ g_set_error (err, g_quark_from_static_string ("lua_logger"),
+ EINVAL, "invalid rspamd{map}");
+ }
+ }
+ else {
+ g_set_error (err, g_quark_from_static_string ("lua_logger"),
+ EINVAL, "unknown class: %s", clsname);
}
/* Metatable, __index, classname */
lua_pop (L, 3);
}
+ else {
+ g_set_error (err, g_quark_from_static_string ("lua_logger"),
+ EINVAL, "no metatable found for userdata");
+ }
return uid;
}
@@ -709,7 +713,8 @@ lua_logger_do_log (lua_State *L,
gchar logbuf[RSPAMD_LOGBUF_SIZE - 128];
const gchar *uid = NULL;
gint fmt_pos = start_pos;
- gboolean ret;
+ gint ret;
+ GError *err = NULL;
if (lua_type (L, start_pos) == LUA_TSTRING) {
fmt_pos = start_pos;
@@ -717,10 +722,17 @@ lua_logger_do_log (lua_State *L,
else if (lua_type (L, start_pos) == LUA_TUSERDATA) {
fmt_pos = start_pos + 1;
- uid = lua_logger_get_id (L, start_pos);
+ uid = lua_logger_get_id (L, start_pos, &err);
if (uid == NULL) {
- return luaL_error (L, "bad userdata for logging");
+ ret = luaL_error (L, "bad userdata for logging: %s",
+ err ? err->message : "unknown error");
+
+ if (err) {
+ g_error_free (err);
+ }
+
+ return ret;
}
}
else {
@@ -793,7 +805,7 @@ lua_logger_logx (lua_State *L)
LUA_TRACE_POINT;
GLogLevelFlags flags = lua_tonumber (L, 1);
- return lua_logger_do_log (L, (flags & G_LOG_LEVEL_MASK), FALSE, 2);
+ return lua_logger_do_log (L, flags, FALSE, 2);
}
@@ -811,7 +823,7 @@ lua_logger_debugm (lua_State *L)
uid = luaL_checkstring (L, 2);
}
else {
- uid = lua_logger_get_id (L, 2);
+ uid = lua_logger_get_id (L, 2, NULL);
}
if (uid && module && lua_type (L, 3) == LUA_TSTRING) {