diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-04-04 23:47:56 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2015-04-04 23:47:56 +0100 |
commit | 5d376e9b1ac313d1ec1bfd296b965c50f434a5f6 (patch) | |
tree | 3444c96a27d36b08dd411a469b93fcedfbed3d78 /src/lua/lua_common.c | |
parent | 359f2f8272d2d396b55412607f0c34b000086337 (diff) | |
download | rspamd-5d376e9b1ac313d1ec1bfd296b965c50f434a5f6.tar.gz rspamd-5d376e9b1ac313d1ec1bfd296b965c50f434a5f6.zip |
Move logger code to a separate module.
Diffstat (limited to 'src/lua/lua_common.c')
-rw-r--r-- | src/lua/lua_common.c | 120 |
1 files changed, 0 insertions, 120 deletions
diff --git a/src/lua/lua_common.c b/src/lua/lua_common.c index d970325d1..1b065c2e6 100644 --- a/src/lua/lua_common.c +++ b/src/lua/lua_common.c @@ -32,21 +32,6 @@ const luaL_reg null_reg[] = { {NULL, NULL} }; -/* Logger methods */ -LUA_FUNCTION_DEF (logger, err); -LUA_FUNCTION_DEF (logger, warn); -LUA_FUNCTION_DEF (logger, info); -LUA_FUNCTION_DEF (logger, debug); - -static const struct luaL_reg loggerlib_f[] = { - LUA_INTERFACE_DEF (logger, err), - LUA_INTERFACE_DEF (logger, warn), - LUA_INTERFACE_DEF (logger, info), - LUA_INTERFACE_DEF (logger, debug), - {"__tostring", rspamd_lua_class_tostring}, - {NULL, NULL} -}; - /* Util functions */ /** @@ -160,111 +145,6 @@ rspamd_lua_table_get (lua_State *L, const gchar *index) } static void -lua_common_log (GLogLevelFlags level, lua_State *L, const gchar *msg) -{ - lua_Debug d; - gchar 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 (rspamd_main->logger, - NULL, - func_buf, - "%s", - msg); - } - else { - rspamd_common_log_function (rspamd_main->logger, - level, - func_buf, - "%s", - msg); - } - } - else { - if (level == G_LOG_LEVEL_DEBUG) { - rspamd_conditional_debug (rspamd_main->logger, - NULL, - __FUNCTION__, - "%s", - msg); - } - else { - rspamd_common_log_function (rspamd_main->logger, - level, - __FUNCTION__, - "%s", - msg); - } - } -} - -/*** Logger interface ***/ -static gint -lua_logger_err (lua_State * L) -{ - const gchar *msg; - msg = luaL_checkstring (L, 1); - lua_common_log (G_LOG_LEVEL_CRITICAL, L, msg); - return 1; -} - -static gint -lua_logger_warn (lua_State * L) -{ - const gchar *msg; - msg = luaL_checkstring (L, 1); - lua_common_log (G_LOG_LEVEL_WARNING, L, msg); - return 1; -} - -static gint -lua_logger_info (lua_State * L) -{ - const gchar *msg; - msg = luaL_checkstring (L, 1); - lua_common_log (G_LOG_LEVEL_INFO, L, msg); - return 1; -} - -static gint -lua_logger_debug (lua_State * L) -{ - const gchar *msg; - msg = luaL_checkstring (L, 1); - lua_common_log (G_LOG_LEVEL_DEBUG, L, msg); - return 1; -} - - -/*** Init functions ***/ - -static gint -lua_load_logger (lua_State *L) -{ - lua_newtable (L); - luaL_register (L, NULL, loggerlib_f); - - return 1; -} - -static void -luaopen_logger (lua_State * L) -{ - rspamd_lua_add_preload (L, "rspamd_logger", lua_load_logger); -} - - -static void lua_add_actions_global (lua_State *L) { gint i; |