aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorVsevolod Stakhov <vsevolod@highsecure.ru>2016-11-25 17:04:37 +0000
committerVsevolod Stakhov <vsevolod@highsecure.ru>2016-11-25 17:04:37 +0000
commit1b5bf8f88aadec05439c3657c15e4d8205226497 (patch)
tree92ca8c8822f3b6ced8c934b13bbf86c066e3f0a2 /src
parent6c2e9334dcc350c917c9a6850ebf0e8386441609 (diff)
downloadrspamd-1b5bf8f88aadec05439c3657c15e4d8205226497.tar.gz
rspamd-1b5bf8f88aadec05439c3657c15e4d8205226497.zip
[Feature] Add logger.debugm to debug lua modules
Diffstat (limited to 'src')
-rw-r--r--src/lua/lua_logger.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/lua/lua_logger.c b/src/lua/lua_logger.c
index c981a35bf..4e10cc9c9 100644
--- a/src/lua/lua_logger.c
+++ b/src/lua/lua_logger.c
@@ -108,6 +108,16 @@ LUA_FUNCTION_DEF (logger, infox);
* @param {any} args list of arguments to be replaced in %<number> positions
*/
LUA_FUNCTION_DEF (logger, debugx);
+
+/***
+ * @function logger.debugm(module, id, fmt[, args)
+ * Extended interface to make a debug log message
+ * @param {string} module debug module
+ * @param {task|cfg|pool|string} id id to log
+ * @param {string} fmt format string, arguments are encoded as %<number>
+ * @param {any} args list of arguments to be replaced in %<number> positions
+ */
+LUA_FUNCTION_DEF (logger, debugm);
/***
* @function logger.slog(fmt[, args)
* Create string replacing percent params with corresponding arguments
@@ -126,6 +136,7 @@ static const struct luaL_reg loggerlib_f[] = {
LUA_INTERFACE_DEF (logger, warnx),
LUA_INTERFACE_DEF (logger, infox),
LUA_INTERFACE_DEF (logger, debugx),
+ LUA_INTERFACE_DEF (logger, debugm),
LUA_INTERFACE_DEF (logger, slog),
{"__tostring", rspamd_lua_class_tostring},
{NULL, NULL}
@@ -706,6 +717,38 @@ lua_logger_debugx (lua_State *L)
}
static gint
+lua_logger_debugm (lua_State *L)
+{
+ gchar logbuf[RSPAMD_LOGBUF_SIZE - 128];
+ const gchar *uid = NULL, *module = NULL;
+ gboolean ret;
+
+ module = luaL_checkstring (L, 1);
+
+ if (lua_type (L, 2) == LUA_TSTRING) {
+ uid = luaL_checkstring (L, 2);
+ }
+ else {
+ uid = lua_logger_get_id (L, 2);
+ }
+
+ if (uid && module && lua_type (L, 3) == LUA_TSTRING) {
+ ret = lua_logger_log_format (L, 3, FALSE, logbuf, sizeof (logbuf) - 1);
+
+ if (ret) {
+ lua_common_log_line (G_LOG_LEVEL_DEBUG, L, logbuf, uid, module);
+ }
+ }
+ else {
+ return luaL_error (L, "invalid arguments");
+ }
+
+ return 0;
+}
+
+
+
+static gint
lua_logger_slog (lua_State *L)
{
return lua_logger_logx (L, 0, TRUE);