.. warning:: Verbose logging has significant performance impact on resolver and might also overload you logging system because one request can easily generate tens of kilobytes of logs. Always use appropriate `Filters`_ to limit number of requests triggering this action to a minimum!
.. note:: ``test_function`` is evaluated only when request is finished. As a result verbose logs for all requests must be collected until request is finished because it is not possible to know beforehand how ``test_function`` at the end evaluates given request. When a request is finalized logs are either printed or thrown away.
+ In globally-set verbose mode those lines get printed regardless of the test function and immediately.
Example usage which gathers verbose logs for all requests in subtree ``dnssec-failed.org.`` and prints verbose logs for all requests finished with states different than ``kres.DONE`` (most importantly ``kres.FAIL``, see :c:type:`kr_layer_state`).
function policy.DEBUG_ALWAYS(state, req)
policy.QTRACE(state, req)
- req:trace_chain_callbacks(debug_logline_cb, debug_logfinish_cb)
+ local logline_maybe = nil -- verbose() is immediate and cheaper than callback
+ if not verbose() then logline_maybe = debug_logline_cb end
+ req:trace_chain_callbacks(logline_maybe, debug_logfinish_cb)
policy.REQTRACE(state, req)
end
end)
ffi.gc(debug_stashlog_cb, free_cb)
--- buffer verbose logs and print then only if test() returns a truthy value
+-- buffer verbose logs and print then if test() returns a truthy value (or in verbose mode)
function policy.DEBUG_IF(test)
local debug_finish_cb = ffi.cast('trace_callback_f', function (cbreq)
jit.off(true, true) -- JIT for (C -> lua)^2 nesting isn't allowed
- if test(cbreq) then
+ if verbose() or test(cbreq) then
debug_logfinish_cb(cbreq) -- unconditional version
local stash = cbreq:vars()['policy_debug_stash']
io.write(table.concat(stash, ''))
return function (state, req)
req:vars()['policy_debug_stash'] = {}
policy.QTRACE(state, req)
- req:trace_chain_callbacks(debug_stashlog_cb, debug_finish_cb)
+ local logline_maybe = nil -- verbose() is immediate and cheaper than callback
+ if not verbose() then logline_maybe = debug_logline_cb end
+ req:trace_chain_callbacks(logline_maybe, debug_finish_cb)
policy.REQTRACE(state, req)
return
end