]> git.ipfire.org Git - thirdparty/rspamd.git/commitdiff
Add tests and fix some issues.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 3 Sep 2015 15:56:58 +0000 (16:56 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 3 Sep 2015 15:56:58 +0000 (16:56 +0100)
src/lua/lua_logger.c
test/lua/unit/logger.lua

index ab1f49e4a80ad8201026c301a51646ef293cb133..d82237f5527be2d431004be81f379cb551629508 100644 (file)
@@ -47,8 +47,10 @@ local e = {
 }
 
 -- New extended interface
+-- %<number> 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 */
index e382ab7e482ab23803a5b29229901098d394d811..29ff4c891c6c099912de385b43fa88096e6e237a 100644 (file)
@@ -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