From: Otto Moerbeek Date: Wed, 16 Feb 2022 07:39:33 +0000 (+0100) Subject: Move to structured logging for taskq. As this is almost 100% X-Git-Tag: rec-4.7.0-alpha1~10^2~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=90883655b784e280d9bce13ebc57f7aa491c137e;p=thirdparty%2Fpdns.git Move to structured logging for taskq. As this is almost 100% debug only logging, no backward compat mode --- diff --git a/pdns/recursordist/rec-taskqueue.cc b/pdns/recursordist/rec-taskqueue.cc index b9b8a61b68..4e2f5f1f23 100644 --- a/pdns/recursordist/rec-taskqueue.cc +++ b/pdns/recursordist/rec-taskqueue.cc @@ -22,7 +22,7 @@ #include "rec-taskqueue.hh" #include "taskqueue.hh" #include "lock.hh" -#include "logger.hh" +#include "logging.hh" #include "stat_t.hh" #include "syncres.hh" @@ -45,35 +45,36 @@ static struct taskstats s_resolve_tasks; static void resolve(const struct timeval& now, bool logErrors, const pdns::ResolveTask& task) noexcept { + auto log = g_slog->withName("taskq")->withValues("name", Logging::Loggable(task.d_qname), "qtype", Logging::Loggable(QType(task.d_qtype).toString())); const string msg = "Exception while running a background ResolveTask"; SyncRes sr(now); vector ret; sr.setRefreshAlmostExpired(task.d_refreshMode); bool ex = true; try { - g_log << Logger::Debug << "TaskQueue: resolving " << task.d_qname.toString() << '|' << QType(task.d_qtype).toString() << endl; + log->info(Logr::Debug, "resolving"); int res = sr.beginResolve(task.d_qname, QType(task.d_qtype), QClass::IN, ret); ex = false; - g_log << Logger::Debug << "TaskQueue: DONE resolving " << task.d_qname.toString() << '|' << QType(task.d_qtype).toString() << ": " << res << endl; + log->info(Logr::Debug, "done", "rcode", Logging::Loggable(res), "records", Logging::Loggable(ret.size())); } catch (const std::exception& e) { - g_log << Logger::Error << msg << ": " << e.what() << endl; + log->error(Logr::Error, msg, e.what()); } catch (const PDNSException& e) { - g_log << Logger::Notice << msg << ": " << e.reason << endl; + log->error(Logr::Error, msg, e.reason); } catch (const ImmediateServFailException& e) { if (logErrors) { - g_log << Logger::Notice << msg << ": " << e.reason << endl; + log->error(Logr::Error, msg, e.reason); } } catch (const PolicyHitException& e) { if (logErrors) { - g_log << Logger::Notice << msg << ": PolicyHit" << endl; + log->error(Logr::Notice, msg, "PolicyHit"); } } catch (...) { - g_log << Logger::Error << msg << endl; + log->error(Logr::Error, msg, "Unexpectec exception"); } if (ex) { if (task.d_refreshMode) { diff --git a/pdns/recursordist/taskqueue.cc b/pdns/recursordist/taskqueue.cc index cc1a4b4be7..7e810015b2 100644 --- a/pdns/recursordist/taskqueue.cc +++ b/pdns/recursordist/taskqueue.cc @@ -22,7 +22,7 @@ #include "taskqueue.hh" -#include "logger.hh" +#include "logging.hh" #include "syncres.hh" namespace pdns @@ -47,7 +47,8 @@ ResolveTask TaskQueue::pop() bool ResolveTask::run(bool logErrors) { if (!d_func) { - g_log << Logger::Debug << "TaskQueue: null task for " << d_qname.toString() << '|' << QType(d_qtype).toString() << endl; + auto log = g_slog->withName("taskq")->withValues("name", Logging::Loggable(d_qname), "qtype", Logging::Loggable(QType(d_qtype).toString())); + log->error(Logr::Debug, "null task"); return false; } struct timeval now; @@ -57,7 +58,8 @@ bool ResolveTask::run(bool logErrors) } else { // Deadline passed - g_log << Logger::Debug << "TaskQueue: deadline for " << d_qname.toString() << '|' << QType(d_qtype).toString() << " passed" << endl; + auto log = g_slog->withName("taskq")->withValues("name", Logging::Loggable(d_qname), "qtype", Logging::Loggable(QType(d_qtype).toString())); + log->error(Logr::Debug, "deadline passed"); return true; } return false; diff --git a/pdns/recursordist/taskqueue.hh b/pdns/recursordist/taskqueue.hh index 624d87d1d5..a457823138 100644 --- a/pdns/recursordist/taskqueue.hh +++ b/pdns/recursordist/taskqueue.hh @@ -49,7 +49,7 @@ struct ResolveTask bool operator<(const ResolveTask& a) const { - return tie(d_qname, d_qtype, d_refreshMode) < tie(d_qname, d_qtype, d_refreshMode); + return std::tie(d_qname, d_qtype, d_refreshMode) < std::tie(d_qname, d_qtype, d_refreshMode); } bool run(bool logErrors); };