diff options
34 files changed, 67 insertions, 82 deletions
diff --git a/ci/respdiff/kresd.config b/ci/respdiff/kresd.config index 0539cec7..6a26cabc 100644 --- a/ci/respdiff/kresd.config +++ b/ci/respdiff/kresd.config @@ -23,4 +23,4 @@ modules = { local _, up_bs = net.bufsize() net.bufsize(4096, up_bs) -set_log_level('debug') +log_level('debug') diff --git a/daemon/cache.test/clear.test.lua b/daemon/cache.test/clear.test.lua index c2da41cf..62228948 100644 --- a/daemon/cache.test/clear.test.lua +++ b/daemon/cache.test/clear.test.lua @@ -15,7 +15,7 @@ end policy.add(policy.suffix(policy.PASS, {todname('test.')})) cache.size = 2*MB --- set_log_level('debug') +-- log_level('debug') -- Self-checks on globals assert(help() ~= nil) diff --git a/daemon/cache.test/insert_ns.test.integr/kresd_config.j2 b/daemon/cache.test/insert_ns.test.integr/kresd_config.j2 index 11e13c9c..ac83d20f 100644 --- a/daemon/cache.test/insert_ns.test.integr/kresd_config.j2 +++ b/daemon/cache.test/insert_ns.test.integr/kresd_config.j2 @@ -48,7 +48,7 @@ if detect_time_skew then end _hint_root_file('hints') -set_log_level('debug') +log_level('debug') {% endraw %} net = { '{{SELF_ADDR}}' } diff --git a/daemon/engine.c b/daemon/engine.c index 889d886f..116f6cc6 100644 --- a/daemon/engine.c +++ b/daemon/engine.c @@ -74,7 +74,7 @@ static int l_help(lua_State *L) "hostname()\n hostname\n" "package_version()\n return package version\n" "user(name[, group])\n change process user (and group)\n" - "set_log_level\n logging level (crit, err, warning, notice, info or debug)\n" + "log_level(level)\n logging level (crit, err, warning, notice, info or debug)\n" "option(opt[, new_val])\n get/set server option\n" "mode(strict|normal|permissive)\n set resolver strictness level\n" "reorder_RR([true|false])\n set/get reordering of RRs within RRsets\n" @@ -145,34 +145,35 @@ static int l_quit(lua_State *L) /** Toggle verbose mode. */ static int l_verbose(lua_State *L) { - kr_log_deprecate(SYSTEM, "use set_log_level() instead of verbose()\n"); + kr_log_deprecate(SYSTEM, "use log_level() instead of verbose()\n"); if (lua_isboolean(L, 1) || lua_isnumber(L, 1)) { kr_log_level_set(lua_toboolean(L, 1) == true ? LOG_DEBUG : LOG_DEFAULT_LEVEL); } - lua_pushboolean(L, kr_log_level_get() == LOG_DEBUG); + lua_pushboolean(L, kr_log_level == LOG_DEBUG); return 1; } -static int l_set_log_level(lua_State *L) +static int l_log_level(lua_State *L) { - if (lua_gettop(L) != 1 || !lua_isstring(L, 1)) { - lua_error_p(L, "takes one string parameter"); - return 0; + const int params = lua_gettop(L); + if (params > 1) { + goto bad_call; + } else if (params == 1) { // set + const char *lvl_str = lua_tostring(L, 1); + if (!lvl_str) + goto bad_call; + kr_log_level_t lvl = kr_log_name2level(lvl_str); + if (lvl < 0) + lua_error_p(L, "unknown log level '%s'", lvl_str); + kr_log_level_set(lvl); } - - kr_log_level_t lvl = kr_log_name2level(lua_tostring(L, 1)); - lvl = kr_log_level_set(lvl); - - lua_pushstring(L, kr_log_level2name(lvl)); - return 1; -} - -static int l_get_log_level(lua_State *L) -{ - lua_pushstring(L, kr_log_level2name(kr_log_level_get())); + // get + lua_pushstring(L, kr_log_level2name(kr_log_level)); return 1; +bad_call: + lua_error_p(L, "takes one string parameter or nothing"); } static int l_set_log_target(lua_State *L) @@ -547,10 +548,8 @@ static int init_state(struct engine *engine) lua_setglobal(engine->L, "package_version"); lua_pushcfunction(engine->L, l_verbose); lua_setglobal(engine->L, "verbose"); - lua_pushcfunction(engine->L, l_set_log_level); - 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_log_level); + lua_setglobal(engine->L, "log_level"); lua_pushcfunction(engine->L, l_set_log_target); lua_setglobal(engine->L, "set_log_target"); lua_pushcfunction(engine->L, l_add_log_groups); diff --git a/daemon/lua/map.test.integr/kresd_config.j2 b/daemon/lua/map.test.integr/kresd_config.j2 index 086dab9f..5c9cd123 100644 --- a/daemon/lua/map.test.integr/kresd_config.j2 +++ b/daemon/lua/map.test.integr/kresd_config.j2 @@ -39,7 +39,7 @@ net.listen(worker.control_path .. worker.pid, nil, {kind = 'control'}) assert(#net.list() >= 3) -- UDP, TCP, control -- debug, kept for future use ---set_log_level("debug") +--log_level("debug") log_debug(ffi.C.LOG_GRP_TESTS, '%s', worker.control_path) log_debug(ffi.C.LOG_GRP_TESTS, '%s', table_print(net.list())) diff --git a/daemon/scripting.rst b/daemon/scripting.rst index 5cc8a045..e52a850a 100644 --- a/daemon/scripting.rst +++ b/daemon/scripting.rst @@ -53,7 +53,7 @@ The *direct output* of commands sent over socket is captured and sent back, which gives you an immediate response on the outcome of your command. The commands and their output are also logged in ``contrl`` group, on ``debug`` level if successful or ``warning`` level if failed -(see around :func:`set_log_level`). +(see around :func:`log_level`). Control sockets are also a way to enumerate and test running instances, the list of sockets corresponds to the list of processes, and you can test the diff --git a/doc/config-logging-monitoring.rst b/doc/config-logging-monitoring.rst index 6250a4fe..c600bd68 100644 --- a/doc/config-logging-monitoring.rst +++ b/doc/config-logging-monitoring.rst @@ -10,7 +10,7 @@ E.g. on distributions using systemd-journald use command ``journalctl -u kresd@* Knot Resolver supports 6 logging levels - ``crit``, ``err``, ``warning``, ``notice``, ``info``, ``debug``. All levels with the same meaning as is defined in ``syslog.h``. It is possible change logging level using -:func:`set_log_level` function. +:func:`log_level` function. Logging level ``notice`` is set after start by default, so logs from Knot Resolver should contain only couple lines a day. @@ -20,20 +20,20 @@ In addition to levels, logging is also divided into the :ref:`groups <config_log_groups>`. All groups are logged by default, but you can enable ``debug`` level for some groups using :func:`add_log_groups` function. Other groups are logged to the log level -set by :func:`set_log_level`. +set by :func:`log_level`. -.. py:function:: set_log_level(level) +.. py:function:: log_level([level]) - :param: String ``'crit'``, ``'err'``, ``'warning'``, ``'notice'``, - ``'info'`` or ``'debug'``. + :param: string ``'crit'``, ``'err'``, ``'warning'``, ``'notice'``, + ``'info'`` or ``'debug'`` :return: string Current logging level. - Set global logging level. + Pass a string to set the global logging level. .. py:function:: verbose([true | false]) .. deprecated:: 5.4.0 - Use :func:`set_log_level` instead. + Use :func:`log_level` instead. :param: ``true`` enable ``debug`` level, ``false`` switch to default level (``notice``). :return: boolean ``true`` when ``debug`` level is enabled. @@ -42,12 +42,6 @@ set by :func:`set_log_level`. On busy systems vebose logging can produce several MB of logs per second and will slow down operation. -.. py:function:: get_log_level() - - :return: string Current logging level. - - Show current logging level. - .. py:function:: set_log_target(target) :param: String ``'syslog'``, ``'stderr'``, ``'stdout'`` @@ -75,7 +69,7 @@ set by :func:`set_log_level`. :param: :ref:`Groups <config_log_groups>` switched to global logging level. Switch selected :ref:`groups <config_log_groups>` to logging level set - by :func:`set_log_level`. + by :func:`log_level`. It is also possible to enable ``debug`` logging level for *a single request*, see chapter :ref:`mod-http-trace`. diff --git a/doc/config-overview.rst b/doc/config-overview.rst index 3d0f3c69..ba47be45 100644 --- a/doc/config-overview.rst +++ b/doc/config-overview.rst @@ -62,9 +62,9 @@ The **interactive prompt** is denoted by ``>``, so all examples starting with `` > -- this is a comment entered into interactive prompt > -- comments have no effect here > -- the next line shows a command entered interactivelly and its output - > get_log_level() + > log_level() 'notice' - > -- the previous line without > character is output from get_log_level() command + > -- the previous line without > character is output from log_level() command Following example demontrates how to interactivelly list all currently loaded modules, and includes multi-line output: diff --git a/doc/upgrading.rst b/doc/upgrading.rst index a794522f..5694a4ce 100644 --- a/doc/upgrading.rst +++ b/doc/upgrading.rst @@ -23,7 +23,7 @@ newer versions when they are released. Preferred way to manage :ref:`systemd-multiple-instances` is to use a process manager, e.g. systemd_ or supervisord_. * Function :func:`verbose` is deprecated and will be eventually removed. - Prefered way to change logging level is use to :func:`set_log_level`. + Prefered way to change logging level is use to :func:`log_level`. .. _`systemd`: https://systemd.io/ .. _`supervisord`: http://supervisord.org/ @@ -36,7 +36,7 @@ Configuration file * ``kind='doh'`` in :func:`net.listen` was renamed to ``kind='doh_legacy'``. It is recommended to switch to the new DoH implementation with ``kind='doh2'``. * :func:`verbose` is deprecated. In case you want to change logging level, - there is new function :func:`set_log_level`. + there is new function :func:`log_level`. Packagers & Developers ---------------------- diff --git a/etc/config/config.docker b/etc/config/config.docker index bfededb5..84246000 100644 --- a/etc/config/config.docker +++ b/etc/config/config.docker @@ -36,7 +36,7 @@ function interactive_mode() .. '8453 -> web interface\n' .. '\n' .. 'For verbose logging enter following command to prompt below:\n' - .. 'set_log_level("debug")\n') + .. 'log_level("debug")\n') end print_help() end @@ -62,7 +62,7 @@ function debug_mode(qname, qtype) -- execute query right after start up and exit when the query is finished event.after(0, function() -- ultra verbose log - set_log_level('debug') + log_level('debug') policy.add(policy.all(policy.DEBUG_ALWAYS)) log_debug(ffi.C.LOG_GRP_RESOLVER, 'starting DNS query for %s %s', qname, kres.tostring.type[qtype]) local starttime = cqueues.monotime() diff --git a/lib/cache/overflow.test.integr/kresd_config.j2 b/lib/cache/overflow.test.integr/kresd_config.j2 index 6279bb56..63841ff2 100644 --- a/lib/cache/overflow.test.integr/kresd_config.j2 +++ b/lib/cache/overflow.test.integr/kresd_config.j2 @@ -29,7 +29,7 @@ if detect_time_skew then modules.unload('detect_time_skew') end -set_log_level('debug') +log_level('debug') policy.add(policy.all(policy.DEBUG_ALWAYS)) cache.open(1*MB) diff --git a/lib/cache/test.integr/kresd_config.j2 b/lib/cache/test.integr/kresd_config.j2 index b1ae409e..c4c286f6 100644 --- a/lib/cache/test.integr/kresd_config.j2 +++ b/lib/cache/test.integr/kresd_config.j2 @@ -26,7 +26,7 @@ end _hint_root_file('hints') cache.size = 2*MB -set_log_level('debug') +log_level('debug') policy.add(policy.all(policy.DEBUG_ALWAYS)) {% endraw %} diff --git a/lib/layer/test.integr/kresd_config.j2 b/lib/layer/test.integr/kresd_config.j2 index 3bcd645b..dc18a1b1 100644 --- a/lib/layer/test.integr/kresd_config.j2 +++ b/lib/layer/test.integr/kresd_config.j2 @@ -63,7 +63,7 @@ end _hint_root_file('hints') cache.size = 2*MB -set_log_level('debug') +log_level('debug') policy.add(policy.all(policy.DEBUG_ALWAYS)) {% endraw %} diff --git a/lib/layer/validate.test.integr/kresd_config.j2 b/lib/layer/validate.test.integr/kresd_config.j2 index 47aaee1d..cc0dbd5a 100644 --- a/lib/layer/validate.test.integr/kresd_config.j2 +++ b/lib/layer/validate.test.integr/kresd_config.j2 @@ -27,7 +27,7 @@ if detect_time_skew then end cache.size = 2*MB -set_log_level('debug') +log_level('debug') policy.add(policy.all(policy.DEBUG_ALWAYS)) policy.add(policy.all(policy.FORWARD('8.8.8.8'))) {% endraw %} @@ -209,11 +209,11 @@ static void kr_gnutls_log_level_set() } } -int kr_log_level_set(kr_log_level_t level) +void kr_log_level_set(kr_log_level_t level) { if (level < LOG_CRIT || level > LOG_DEBUG) { kr_log_warning(SYSTEM, "invalid log level\n"); - return kr_log_level; + return; } kr_log_level = level; @@ -221,13 +221,7 @@ int kr_log_level_set(kr_log_level_t level) kr_gnutls_log_level_set(); - return kr_log_level; - -} - -kr_log_level_t kr_log_level_get(void) -{ - return kr_log_level; + return; } void kr_log_add_group(enum kr_log_group group) @@ -146,9 +146,7 @@ KR_EXPORT KR_PRINTF(6) void kr_log_fmt(enum kr_log_group group, kr_log_level_t level, const char *file, const char *line, const char *func, const char *fmt, ...); KR_EXPORT -int kr_log_level_set(kr_log_level_t level); -KR_EXPORT -kr_log_level_t kr_log_level_get(void); +void kr_log_level_set(kr_log_level_t level); KR_EXPORT void kr_log_target_set(kr_log_target_t target); diff --git a/modules/bogus_log/test.integr/kresd_config.j2 b/modules/bogus_log/test.integr/kresd_config.j2 index 2b299dab..0471a274 100644 --- a/modules/bogus_log/test.integr/kresd_config.j2 +++ b/modules/bogus_log/test.integr/kresd_config.j2 @@ -59,7 +59,7 @@ end _hint_root_file('hints') cache.size = 2*MB -set_log_level('debug') +log_level('debug') {% endraw %} net = { '{{SELF_ADDR}}' } diff --git a/modules/daf/test.integr/kresd_config.j2 b/modules/daf/test.integr/kresd_config.j2 index 60fc0820..0381f77e 100644 --- a/modules/daf/test.integr/kresd_config.j2 +++ b/modules/daf/test.integr/kresd_config.j2 @@ -34,7 +34,7 @@ policy.add(policy.suffix(policy.PASS, {todname('test.')})) _hint_root_file('hints') cache.size = 2*MB -set_log_level('debug') +log_level('debug') {% endraw %} net = { '{{SELF_ADDR}}' } diff --git a/modules/policy/README.rst b/modules/policy/README.rst index b981f3bb..fd90dfe7 100644 --- a/modules/policy/README.rst +++ b/modules/policy/README.rst @@ -204,7 +204,7 @@ Following actions act on request and then processing continue until first non-ch .. py:attribute:: QTRACE Pretty-print DNS response packets from authoritative servers into debug logs for the query and its sub-queries. It's useful for debugging weird DNS servers. - Note that debug-level logs are off by default; see :func:`set_log_level`. + Note that debug-level logs are off by default; see :func:`log_level`. .. code-block:: lua @@ -215,7 +215,7 @@ Following actions act on request and then processing continue until first non-ch .. py:attribute:: REQTRACE Pretty-print DNS requests from clients into the verbose log. It's useful for debugging weird DNS clients. - Debug-level logging must be enabled for this policy to be effective; see :func:`set_log_level`. + Debug-level logging must be enabled for this policy to be effective; see :func:`log_level`. It makes most sense together with :ref:`mod-view` (enabling per-client) and probably with verbose logging those request (e.g. ``DEBUG_ALWAYS``). diff --git a/modules/policy/noipv6.test.integr/kresd_config.j2 b/modules/policy/noipv6.test.integr/kresd_config.j2 index 31e28d7f..a897d17c 100644 --- a/modules/policy/noipv6.test.integr/kresd_config.j2 +++ b/modules/policy/noipv6.test.integr/kresd_config.j2 @@ -28,7 +28,7 @@ end _hint_root_file('hints') cache.size = 2*MB -set_log_level('debug') +log_level('debug') {% endraw %} net = { '{{SELF_ADDR}}' } diff --git a/modules/policy/noipvx.test.integr/kresd_config.j2 b/modules/policy/noipvx.test.integr/kresd_config.j2 index 027331ff..87873e84 100644 --- a/modules/policy/noipvx.test.integr/kresd_config.j2 +++ b/modules/policy/noipvx.test.integr/kresd_config.j2 @@ -29,7 +29,7 @@ end _hint_root_file('hints') cache.size = 2*MB -set_log_level('debug') +log_level('debug') {% endraw %} net = { '{{SELF_ADDR}}' } diff --git a/modules/policy/test.integr/kresd_config.j2 b/modules/policy/test.integr/kresd_config.j2 index 180d6186..4ba83dd6 100644 --- a/modules/policy/test.integr/kresd_config.j2 +++ b/modules/policy/test.integr/kresd_config.j2 @@ -27,7 +27,7 @@ end _hint_root_file('hints') cache.size = 2*MB -set_log_level('debug') +log_level('debug') {% endraw %} net = { '{{SELF_ADDR}}' } diff --git a/modules/prefill/prefill.test/prefill.test.lua b/modules/prefill/prefill.test/prefill.test.lua index 05dcb2cf..24befd76 100644 --- a/modules/prefill/prefill.test/prefill.test.lua +++ b/modules/prefill/prefill.test/prefill.test.lua @@ -14,7 +14,7 @@ end policy.add(policy.suffix(policy.PASS, {todname('test.')})) cache.size = 2*MB --- set_log_level('debug') +-- log_level('debug') -- Self-checks on globals assert(help() ~= nil) diff --git a/modules/rebinding/test.integr/kresd_config.j2 b/modules/rebinding/test.integr/kresd_config.j2 index cc52bc92..aed35519 100644 --- a/modules/rebinding/test.integr/kresd_config.j2 +++ b/modules/rebinding/test.integr/kresd_config.j2 @@ -27,7 +27,7 @@ modules.load('rebinding < iterate') _hint_root_file('hints') cache.size = 2*MB -set_log_level('debug') +log_level('debug') net.ipv6 = false {% endraw %} diff --git a/modules/refuse_nord/test.integr/kresd_config.j2 b/modules/refuse_nord/test.integr/kresd_config.j2 index b7d9ea1b..1abe4e4d 100644 --- a/modules/refuse_nord/test.integr/kresd_config.j2 +++ b/modules/refuse_nord/test.integr/kresd_config.j2 @@ -25,7 +25,7 @@ end _hint_root_file('hints') cache.size = 2*MB -set_log_level('debug') +log_level('debug') {% endraw %} net = { '{{SELF_ADDR}}' } diff --git a/modules/renumber/renumber.test.lua b/modules/renumber/renumber.test.lua index 6703a9d9..a74b609f 100644 --- a/modules/renumber/renumber.test.lua +++ b/modules/renumber/renumber.test.lua @@ -73,7 +73,7 @@ policy.add(policy.all(policy.DEBUG_ALWAYS)) policy.add(policy.suffix(policy.PASS, {todname('test.')})) prepare_cache() -set_log_level('debug') +log_level('debug') modules.load('renumber < cache') renumber.config({ -- Source subnet, destination subnet diff --git a/modules/serve_stale/test.integr/kresd_config.j2 b/modules/serve_stale/test.integr/kresd_config.j2 index d6191896..85708336 100644 --- a/modules/serve_stale/test.integr/kresd_config.j2 +++ b/modules/serve_stale/test.integr/kresd_config.j2 @@ -27,7 +27,7 @@ end _hint_root_file('hints') cache.size = 2*MB -set_log_level('debug') +log_level('debug') {% endraw %} {% if DO_IP6 == "true" %} diff --git a/modules/stats/test.integr/kresd_config.j2 b/modules/stats/test.integr/kresd_config.j2 index 12fc2651..4db7caab 100644 --- a/modules/stats/test.integr/kresd_config.j2 +++ b/modules/stats/test.integr/kresd_config.j2 @@ -83,7 +83,7 @@ end _hint_root_file('hints') cache.size = 2*MB -set_log_level('debug') +log_level('debug') {% endraw %} net = { '{{SELF_ADDR}}' } diff --git a/modules/ta_update/ta_update.test.integr/kresd_config.j2 b/modules/ta_update/ta_update.test.integr/kresd_config.j2 index 74f5586c..da319a28 100644 --- a/modules/ta_update/ta_update.test.integr/kresd_config.j2 +++ b/modules/ta_update/ta_update.test.integr/kresd_config.j2 @@ -22,7 +22,7 @@ end policy.add(policy.suffix(policy.PASS, {todname('test.')})) cache.size = 2*MB -set_log_level('debug') +log_level('debug') {% endraw %} modules.load('hints') diff --git a/modules/ta_update/ta_update.unmanagedkey.test.integr/kresd_config.j2 b/modules/ta_update/ta_update.unmanagedkey.test.integr/kresd_config.j2 index 378a1679..263404d7 100644 --- a/modules/ta_update/ta_update.unmanagedkey.test.integr/kresd_config.j2 +++ b/modules/ta_update/ta_update.unmanagedkey.test.integr/kresd_config.j2 @@ -38,7 +38,7 @@ end policy.add(policy.suffix(policy.PASS, {todname('test.')})) cache.size = 2*MB -set_log_level('debug') +log_level('debug') {% endraw %} modules.load('hints') diff --git a/modules/view/addr.test.integr/kresd_config.j2 b/modules/view/addr.test.integr/kresd_config.j2 index 2d85b742..3dd8d92c 100644 --- a/modules/view/addr.test.integr/kresd_config.j2 +++ b/modules/view/addr.test.integr/kresd_config.j2 @@ -31,7 +31,7 @@ end _hint_root_file('hints') cache.size = 2*MB -set_log_level('debug') +log_level('debug') {% endraw %} net = { '{{SELF_ADDR}}' } diff --git a/modules/view/tsig.test.integr/kresd_config.j2 b/modules/view/tsig.test.integr/kresd_config.j2 index 042da2a8..f04dce24 100644 --- a/modules/view/tsig.test.integr/kresd_config.j2 +++ b/modules/view/tsig.test.integr/kresd_config.j2 @@ -33,7 +33,7 @@ trust_anchors.remove('.') _hint_root_file('hints') cache.size = 2*MB -set_log_level('debug') +log_level('debug') {% endraw %} net = { '{{SELF_ADDR}}' } diff --git a/scripts/kresd-host.lua b/scripts/kresd-host.lua index 1adaef71..be6efd4c 100755 --- a/scripts/kresd-host.lua +++ b/scripts/kresd-host.lua @@ -50,7 +50,7 @@ k = 1 while k <= #arg do verbose = true elseif v == '-d' then verbose = true - table.insert(config, 'set_log_level("debug")') + table.insert(config, 'log_level("debug")') elseif v == '-4' then table.insert(config, 'net.ipv6 = false') elseif v == '-6' then diff --git a/tests/pytests/templates/kresd.conf.j2 b/tests/pytests/templates/kresd.conf.j2 index aa9135e4..550c2247 100644 --- a/tests/pytests/templates/kresd.conf.j2 +++ b/tests/pytests/templates/kresd.conf.j2 @@ -5,7 +5,7 @@ modules = { } {% if kresd.verbose %} -set_log_level('debug') +log_level('debug') {% endif %} {% if kresd.ip %} |