diff options
author | Kim Alvefur <zash@zash.se> | 2021-01-05 20:04:07 +0100 |
---|---|---|
committer | Kim Alvefur <zash@zash.se> | 2021-01-05 20:04:07 +0100 |
commit | 147835b1ecfe9436aeb6f3e11f88031a7d92173b (patch) | |
tree | f9a259742911c9b3666bea35f1f69565d3e8ee3b /net | |
parent | b4403aadddfe80d62290a7b8e98bff2738e834e2 (diff) | |
download | prosody-147835b1ecfe9436aeb6f3e11f88031a7d92173b.tar.gz prosody-147835b1ecfe9436aeb6f3e11f88031a7d92173b.zip |
net.unbound: Allow tracing individual queries with a logger per query
Diffstat (limited to 'net')
-rw-r--r-- | net/unbound.lua | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/net/unbound.lua b/net/unbound.lua index bc196c22..48a8df0e 100644 --- a/net/unbound.lua +++ b/net/unbound.lua @@ -13,10 +13,12 @@ local s_lower = string.lower; local s_upper = string.upper; local noop = function() end; -local log = require "util.logger".init("unbound"); +local logger = require "util.logger"; +local log = logger.init("unbound"); local net_server = require "net.server"; local libunbound = require"lunbound"; local promise = require"util.promise"; +local new_id = require "util.id".medium; local gettime = require"socket".gettime; local dns_utils = require"util.dns"; @@ -104,26 +106,27 @@ local function lookup(callback, qname, qtype, qclass) local ntype, nclass = types[qtype], classes[qclass]; local startedat = gettime(); local ret; + local log_query = logger.init("unbound.query"..new_id()); local function callback_wrapper(a, err) local gotdataat = gettime(); waiting_queries[ret] = nil; if a then prep_answer(a); - log("debug", "Results for %s %s %s: %s (%s, %f sec)", qname, qclass, qtype, a.rcode == 0 and (#a .. " items") or a.status, + log_query("debug", "Results for %s %s %s: %s (%s, %f sec)", qname, qclass, qtype, a.rcode == 0 and (#a .. " items") or a.status, a.secure and "Secure" or a.bogus or "Insecure", gotdataat - startedat); -- Insecure as in unsigned else - log("error", "Results for %s %s %s: %s", qname, qclass, qtype, tostring(err)); + log_query("error", "Results for %s %s %s: %s", qname, qclass, qtype, tostring(err)); end local ok, cerr = pcall(callback, a, err); - if not ok then log("error", "Error in callback: %s", cerr); end + if not ok then log_query("error", "Error in callback: %s", cerr); end end - log("debug", "Resolve %s %s %s", qname, qclass, qtype); + log_query("debug", "Resolve %s %s %s", qname, qclass, qtype); local err; ret, err = unbound:resolve_async(callback_wrapper, qname, ntype, nclass); if ret then waiting_queries[ret] = callback; else - log("warn", "Resolver error: %s", err); + log_query("warn", "Resolver error: %s", err); end return ret, err; end |