From: Vsevolod Stakhov Date: Thu, 3 Sep 2015 15:56:58 +0000 (+0100) Subject: Add tests and fix some issues. X-Git-Tag: 1.0.0~89 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b361af86b99c7e4b6e6f3fcd508b882ffb0c9d9e;p=thirdparty%2Frspamd.git Add tests and fix some issues. --- diff --git a/src/lua/lua_logger.c b/src/lua/lua_logger.c index ab1f49e4a8..d82237f552 100644 --- a/src/lua/lua_logger.c +++ b/src/lua/lua_logger.c @@ -47,8 +47,10 @@ local e = { } -- New extended interface +-- % means numeric arguments and %s means the next argument +-- for example %1, %2, %s: %s would mean the third argument -rspamd_logger.infox('a=%1, b=%2, c=%3, d=%4, e=%5', a, b, c, d, e) +rspamd_logger.infox('a=%1, b=%2, c=%3, d=%4, e=%s', a, b, c, d, e) -- Output: a=string, b=1.50000, c=1, d={[1] = aa, [2] = 1, [3] = bb} e={[key]=value, [key2]=1.0} -- Legacy interface (can handle merely strings) @@ -449,7 +451,6 @@ lua_logger_logx (lua_State *L, GLogLevelFlags level, gboolean is_string) lua_pushstring (L, "__index"); lua_gettable (L, -2); - lua_istable (L, -1); lua_pushstring (L, "class"); lua_gettable (L, -2); @@ -493,7 +494,7 @@ lua_logger_logx (lua_State *L, GLogLevelFlags level, gboolean is_string) s = lua_tostring (L, fmt_pos); c = s; - cur_arg = fmt_pos + 1; + cur_arg = fmt_pos; if (s == NULL) { return 0; @@ -531,7 +532,7 @@ lua_logger_logx (lua_State *L, GLogLevelFlags level, gboolean is_string) arg_num = strtoul (c, NULL, 10); arg_num += fmt_pos - 1; /* Update the current argument */ - cur_arg = arg_num + 1; + cur_arg = arg_num; } else { /* We have non numeric argument, e.g. %s */ diff --git a/test/lua/unit/logger.lua b/test/lua/unit/logger.lua index e382ab7e48..29ff4c891c 100644 --- a/test/lua/unit/logger.lua +++ b/test/lua/unit/logger.lua @@ -11,6 +11,7 @@ context("Logger unit tests", function() {'%1', '{[1] = 1, [2] = test}', {1, 'test'}}, {'%1', '{[k1] = 1, [k2] = test}', {k1=1, k2='test'}}, {'%1', '{[1] = 1, [2] = 2.100000, [k2] = test}', {1, 2.1, k2='test'}}, + {'%s', 'true', true}, } for _,c in ipairs(cases) do