diff options
author | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-07-26 18:48:02 +0400 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@rambler-co.ru> | 2010-07-26 18:48:02 +0400 |
commit | 89b6c2f9260b0a3cea1f80634fbfbcfa71ac71a3 (patch) | |
tree | a3bc4d825c636706d321e20ced35c4c269515834 | |
parent | 0e88083420796af997f1af0396e4ea78ac235ba5 (diff) | |
download | rspamd-89b6c2f9260b0a3cea1f80634fbfbcfa71ac71a3.tar.gz rspamd-89b6c2f9260b0a3cea1f80634fbfbcfa71ac71a3.zip |
* Improve lua logging
-rw-r--r-- | src/lua/lua_common.c | 39 |
1 files changed, 35 insertions, 4 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index 3bf81da55..b0ca3a32b 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -118,6 +118,37 @@ lua_set_table_index (lua_State * L, const char *index, const char *value) lua_settable (L, -3); } +static void +lua_common_log (GLogLevelFlags level, lua_State *L, const char *msg) +{ + lua_Debug d; + char func_buf[128], *p; + + if (lua_getstack (L, 1, &d) == 1) { + (void)lua_getinfo(L, "Sl", &d); + if ((p = strrchr (d.short_src, '/')) == NULL) { + p = d.short_src; + } + else { + p ++; + } + rspamd_snprintf (func_buf, sizeof (func_buf), "%s:%d", p, d.currentline); + if (level == G_LOG_LEVEL_DEBUG) { + rspamd_conditional_debug(-1, func_buf, msg); + } + else { + rspamd_common_log_function(level, func_buf, msg); + } + } + else { + if (level == G_LOG_LEVEL_DEBUG) { + rspamd_conditional_debug(-1, __FUNCTION__, msg); + } + else { + rspamd_common_log_function(level, __FUNCTION__, msg); + } + } +} /*** Logger interface ***/ static int @@ -125,7 +156,7 @@ lua_logger_err (lua_State * L) { const char *msg; msg = luaL_checkstring (L, 2); - msg_err (msg); + lua_common_log (G_LOG_LEVEL_CRITICAL, L, msg); return 1; } @@ -134,7 +165,7 @@ lua_logger_warn (lua_State * L) { const char *msg; msg = luaL_checkstring (L, 2); - msg_warn (msg); + lua_common_log (G_LOG_LEVEL_WARNING, L, msg); return 1; } @@ -143,7 +174,7 @@ lua_logger_info (lua_State * L) { const char *msg; msg = luaL_checkstring (L, 2); - msg_info (msg); + lua_common_log (G_LOG_LEVEL_INFO, L, msg); return 1; } @@ -152,7 +183,7 @@ lua_logger_debug (lua_State * L) { const char *msg; msg = luaL_checkstring (L, 2); - msg_debug (msg); + lua_common_log (G_LOG_LEVEL_DEBUG, L, msg); return 1; } |