]> git.ipfire.org Git - thirdparty/knot-resolver.git/commitdiff
logging: rename *_log_groups() function to plural
authorTomas Krizek <tomas.krizek@nic.cz>
Thu, 8 Jul 2021 14:31:27 +0000 (16:31 +0200)
committerTomas Krizek <tomas.krizek@nic.cz>
Thu, 29 Jul 2021 09:42:33 +0000 (11:42 +0200)
Plural makes more sense to me here, since it can take a table with
multiple entries as input.

daemon/engine.c
daemon/lua/log.test.lua

index 8207474d6b1e8f157fb0450418310c6c8f06d4b5..189e62285a346a7d39c36516210de1f3df25eb28 100644 (file)
@@ -181,7 +181,7 @@ static int handle_log_groups(lua_State *L, void (*action)(log_groups_t grp))
        if (lua_isstring(L, 1)) {
                log_groups_t grp = kr_log_name2grp(lua_tostring(L, 1));
                if (grp == 0)
-                       lua_error_p(L, "unknown group");
+                       lua_error_p(L, "unknown group \"%s\"", lua_tostring(L, -1));
                action(grp);
        }
 
@@ -194,7 +194,7 @@ static int handle_log_groups(lua_State *L, void (*action)(log_groups_t grp))
                                lua_error_p(L, "wrong value at index %d, must be string", idx);
                        grp = kr_log_name2grp(lua_tostring(L, -1));
                        if (grp == 0)
-                               lua_error_p(L, "unknown group \"%s\", type add_log_group() for help.", lua_tostring(L, -1));
+                               lua_error_p(L, "unknown group \"%s\"", lua_tostring(L, -1));
 
                        action(grp);
                        ++idx;
@@ -205,17 +205,17 @@ static int handle_log_groups(lua_State *L, void (*action)(log_groups_t grp))
        return 0;
 }
 
-static int l_add_log_group(lua_State *L)
+static int l_add_log_groups(lua_State *L)
 {
        return handle_log_groups(L, kr_log_add_group);
 }
 
-static int l_del_log_group(lua_State *L)
+static int l_del_log_groups(lua_State *L)
 {
        return handle_log_groups(L, kr_log_del_group);
 }
 
-static int l_get_log_group(lua_State *L)
+static int l_get_log_groups(lua_State *L)
 {
        char* name;
 
@@ -517,12 +517,12 @@ static int init_state(struct engine *engine)
        lua_setglobal(engine->L, "set_log_level");
        lua_pushcfunction(engine->L, l_get_log_level);
        lua_setglobal(engine->L, "get_log_level");
-       lua_pushcfunction(engine->L, l_add_log_group);
-       lua_setglobal(engine->L, "add_log_group");
-       lua_pushcfunction(engine->L, l_del_log_group);
-       lua_setglobal(engine->L, "del_log_group");
-       lua_pushcfunction(engine->L, l_get_log_group);
-       lua_setglobal(engine->L, "get_log_group");
+       lua_pushcfunction(engine->L, l_add_log_groups);
+       lua_setglobal(engine->L, "add_log_groups");
+       lua_pushcfunction(engine->L, l_del_log_groups);
+       lua_setglobal(engine->L, "del_log_groups");
+       lua_pushcfunction(engine->L, l_get_log_groups);
+       lua_setglobal(engine->L, "get_log_groups");
        lua_pushcfunction(engine->L, l_setuser);
        lua_setglobal(engine->L, "user");
        lua_pushcfunction(engine->L, l_hint_root_file);
index 0b73c564c8a79a9417badd58d1f0f33d74f26d21..e3926297b2227228cad84e586eb05643b82b7f4c 100644 (file)
@@ -1,15 +1,25 @@
-local function test_log_group()
-       same(get_log_group()['system'], nil, '"system" log group not logged by default')
-       add_log_group('system')
-       same(get_log_group()['system'], true, 'adding "system" log group')
-       add_log_group('devel')
-       same(get_log_group()['devel'], true, 'adding another ("devel") log group')
-       del_log_group('system')
-       same(get_log_group()['system'], nil, 'removing "system" log group')
-       boom(add_log_group, { 'nonexistent' }, "nonexistent group cant't be added")
-       boom(del_log_group, { 'nonexistent2' }, "nonexistent2 group can't be removed")
+local function test_log_groups()
+       same(get_log_groups()['system'], nil, '"system" log group not logged by default')
+       add_log_groups('system')
+       same(get_log_groups()['system'], true, 'add "system" log group as string')
+       add_log_groups('devel')
+       same(get_log_groups()['devel'], true, 'add another ("devel") log group as string')
+       add_log_groups({ 'cache' })
+       same(get_log_groups()['cache'], true, 'add "cache" log group as table')
+       add_log_groups({ 'io', 'tests' })
+       same(get_log_groups()['io'], true, 'add "io" log group as table with multiple entires')
+       same(get_log_groups()['tests'], true, 'add "tests" log group as table with multiple entries')
+       del_log_groups('system')
+       same(get_log_groups()['system'], nil, 'remove "system" log group as string')
+       del_log_groups({ 'cache' })
+       same(get_log_groups()['cache'], nil, 'remove "cache" log group as table')
+       del_log_groups({ 'io', 'tests' })
+       same(get_log_groups()['io'], nil, 'remove "io" log group as table with multiple entries')
+       same(get_log_groups()['tests'], nil, 'remove "tests" log group as table with multiple entries')
+       boom(add_log_groups, { 'nonexistent' }, "nonexistent group cant't be added")
+       boom(del_log_groups, { 'nonexistent2' }, "nonexistent2 group can't be removed")
 end
 
 return {
-       test_log_group,
+       test_log_groups,
 }