From: Otto Moerbeek Date: Wed, 20 Aug 2025 11:34:23 +0000 (+0200) Subject: Also refactor code conditional on g_slogStructured X-Git-Tag: rec-5.4.0-alpha1~355^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=287983e00d138ba580475ab074a71f02f4e72a8d;p=thirdparty%2Fpdns.git Also refactor code conditional on g_slogStructured Signed-off-by: Otto Moerbeek --- diff --git a/pdns/recursordist/pdns_recursor.cc b/pdns/recursordist/pdns_recursor.cc index a508866564..68387ed048 100644 --- a/pdns/recursordist/pdns_recursor.cc +++ b/pdns/recursordist/pdns_recursor.cc @@ -1186,17 +1186,7 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi } if (!g_quiet || tracedQuery) { - if (!g_slogStructured) { - g_log << Logger::Warning << RecThreadInfo::thread_local_id() << " [" << g_multiTasker->getTid() << "/" << g_multiTasker->numProcesses() << "] " << (comboWriter->d_tcp ? "TCP " : "") << "question for '" << comboWriter->d_mdp.d_qname << "|" - << QType(comboWriter->d_mdp.d_qtype) << "' from " << comboWriter->getRemote(); - if (!comboWriter->d_ednssubnet.getSource().empty()) { - g_log << " (ecs " << comboWriter->d_ednssubnet.getSource().toString() << ")"; - } - g_log << endl; - } - else { - resolver.d_slog->info(Logr::Info, "Question"); - } + resolver.d_slog->info(Logr::Info, "Question"); } if (!comboWriter->d_mdp.d_header.rd) { @@ -1878,34 +1868,21 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi // Now it always uses an integral number of microseconds, except for averages, which use doubles uint64_t spentUsec = uSec(resolver.getNow() - comboWriter->d_now); if (!g_quiet) { - if (!g_slogStructured) { - g_log << Logger::Error << RecThreadInfo::thread_local_id() << " [" << g_multiTasker->getTid() << "/" << g_multiTasker->numProcesses() << "] answer to " << (comboWriter->d_mdp.d_header.rd ? "" : "non-rd ") << "question '" << comboWriter->d_mdp.d_qname << "|" << DNSRecordContent::NumberToType(comboWriter->d_mdp.d_qtype); - g_log << "': " << ntohs(packetWriter.getHeader()->ancount) << " answers, " << ntohs(packetWriter.getHeader()->arcount) << " additional, took " << resolver.d_outqueries << " packets, " << resolver.d_totUsec / 1000.0 << " netw ms, " << static_cast(spentUsec) / 1000.0 << " tot ms, " << resolver.d_throttledqueries << " throttled, " << resolver.d_timeouts << " timeouts, " << resolver.d_tcpoutqueries << "/" << resolver.d_dotoutqueries << " tcp/dot connections, rcode=" << res; - - if (!shouldNotValidate && resolver.isDNSSECValidationRequested()) { - g_log << ", dnssec=" << resolver.getValidationState(); - } - g_log << " answer-is-variable=" << resolver.wasVariable() << ", into-packetcache=" << intoPC; - g_log << " maxdepth=" << resolver.d_maxdepth; - g_log << endl; - } - else { - resolver.d_slog->info(Logr::Info, "Answer", "rd", Logging::Loggable(comboWriter->d_mdp.d_header.rd), - "answers", Logging::Loggable(ntohs(packetWriter.getHeader()->ancount)), - "additional", Logging::Loggable(ntohs(packetWriter.getHeader()->arcount)), - "outqueries", Logging::Loggable(resolver.d_outqueries), - "netms", Logging::Loggable(resolver.d_totUsec / 1000.0), - "totms", Logging::Loggable(static_cast(spentUsec) / 1000.0), - "throttled", Logging::Loggable(resolver.d_throttledqueries), - "timeouts", Logging::Loggable(resolver.d_timeouts), - "tcpout", Logging::Loggable(resolver.d_tcpoutqueries), - "dotout", Logging::Loggable(resolver.d_dotoutqueries), - "rcode", Logging::Loggable(res), - "validationState", Logging::Loggable(resolver.getValidationState()), - "answer-is-variable", Logging::Loggable(resolver.wasVariable()), - "into-packetcache", Logging::Loggable(intoPC), - "maxdepth", Logging::Loggable(resolver.d_maxdepth)); - } + resolver.d_slog->info(Logr::Info, "Answer", "rd", Logging::Loggable(comboWriter->d_mdp.d_header.rd), + "answers", Logging::Loggable(ntohs(packetWriter.getHeader()->ancount)), + "additional", Logging::Loggable(ntohs(packetWriter.getHeader()->arcount)), + "outqueries", Logging::Loggable(resolver.d_outqueries), + "netms", Logging::Loggable(resolver.d_totUsec / 1000.0), + "totms", Logging::Loggable(static_cast(spentUsec) / 1000.0), + "throttled", Logging::Loggable(resolver.d_throttledqueries), + "timeouts", Logging::Loggable(resolver.d_timeouts), + "tcpout", Logging::Loggable(resolver.d_tcpoutqueries), + "dotout", Logging::Loggable(resolver.d_dotoutqueries), + "rcode", Logging::Loggable(res), + "validationState", Logging::Loggable(resolver.getValidationState()), + "answer-is-variable", Logging::Loggable(resolver.wasVariable()), + "into-packetcache", Logging::Loggable(intoPC), + "maxdepth", Logging::Loggable(resolver.d_maxdepth)); } if (comboWriter->d_mdp.d_header.opcode == static_cast(Opcode::Query)) { @@ -1957,9 +1934,7 @@ void startDoResolve(void* arg) // NOLINT(readability-function-cognitive-complexi resolver.d_slog->error(Logr::Error, ne.what(), "Nested exception in resolver context", Logging::Loggable("std::exception")); } catch (...) { - } - if (!g_slogStructured) { - g_log << endl; + ; } } catch (...) { diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index 52669e277e..9af1314910 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -201,28 +201,10 @@ static void setCPUMap(const std::map>& cpusMap, unsi } int ret = mapThreadToCPUList(tid, cpuMapping->second); if (ret == 0) { - if (!g_slogStructured) { - g_log << Logger::Info << "CPU affinity for thread " << n << " has been set to CPU map:"; - for (const auto cpu : cpuMapping->second) { - g_log << Logger::Info << " " << cpu; - } - g_log << Logger::Info << endl; - } - else { - log->info(Logr::Info, "CPU affinity has been set", "thread", Logging::Loggable(n), "cpumap", Logging::IterLoggable(cpuMapping->second.begin(), cpuMapping->second.end())); - } + log->info(Logr::Info, "CPU affinity has been set", "thread", Logging::Loggable(n), "cpumap", Logging::IterLoggable(cpuMapping->second.begin(), cpuMapping->second.end())); } else { - if (!g_slogStructured) { - g_log << Logger::Warning << "Error setting CPU affinity for thread " << n << " to CPU map:"; - for (const auto cpu : cpuMapping->second) { - g_log << Logger::Info << " " << cpu; - } - g_log << Logger::Info << ' ' << stringerror(ret) << endl; - } - else { - log->error(Logr::Warning, ret, "Error setting CPU affinity", "thread", Logging::Loggable(n), "cpumap", Logging::IterLoggable(cpuMapping->second.begin(), cpuMapping->second.end())); - } + log->error(Logr::Warning, ret, "Error setting CPU affinity", "thread", Logging::Loggable(n), "cpumap", Logging::IterLoggable(cpuMapping->second.begin(), cpuMapping->second.end())); } } @@ -1330,19 +1312,7 @@ static std::shared_ptr parseACL(const std::string& aclFile, const for (const auto& address : ips) { result->addMask(address); } - if (!g_slogStructured) { - g_log << Logger::Info << aclSetting << ": "; - for (auto i = ips.begin(); i != ips.end(); ++i) { - if (i != ips.begin()) { - g_log << Logger::Info << ", "; - } - g_log << Logger::Info << *i; - } - g_log << Logger::Info << endl; - } - else { - log->info(Logr::Info, "Setting access control", "acl", Logging::Loggable(aclSetting), "addresses", Logging::IterLoggable(ips.begin(), ips.end())); - } + log->info(Logr::Info, "Setting access control", "acl", Logging::Loggable(aclSetting), "addresses", Logging::IterLoggable(ips.begin(), ips.end())); } return result; @@ -1723,19 +1693,7 @@ static int initDNSSEC(Logr::log_t log) } } if (!nums.empty()) { - if (!g_slogStructured) { - g_log << Logger::Warning << (automatic ? "Automatically" : "Manually") << " disabled DNSSEC algorithms: "; - for (auto i = nums.begin(); i != nums.end(); ++i) { - if (i != nums.begin()) { - g_log << Logger::Warning << ", "; - } - g_log << Logger::Warning << *i; - } - g_log << Logger::Warning << endl; - } - else { - log->info(Logr::Notice, "Disabled DNSSEC algorithms", "automatically", Logging::Loggable(automatic), "algorithms", Logging::IterLoggable(nums.begin(), nums.end())); - } + log->info(Logr::Notice, "Disabled DNSSEC algorithms", "automatically", Logging::Loggable(automatic), "algorithms", Logging::IterLoggable(nums.begin(), nums.end())); } return 0; @@ -1752,19 +1710,7 @@ static void initDontQuery(Logr::log_t log) for (const auto& anIP : ips) { SyncRes::addDontQuery(anIP); } - if (!g_slogStructured) { - g_log << Logger::Warning << "Will not send queries to: "; - for (auto i = ips.begin(); i != ips.end(); ++i) { - if (i != ips.begin()) { - g_log << Logger::Warning << ", "; - } - g_log << Logger::Warning << *i; - } - g_log << Logger::Warning << endl; - } - else { - log->info(Logr::Notice, "Will not send queries to", "addresses", Logging::IterLoggable(ips.begin(), ips.end())); - } + log->info(Logr::Notice, "Will not send queries to", "addresses", Logging::IterLoggable(ips.begin(), ips.end())); } } diff --git a/pdns/recursordist/reczones.cc b/pdns/recursordist/reczones.cc index fea92f138d..dba5c5dcdd 100644 --- a/pdns/recursordist/reczones.cc +++ b/pdns/recursordist/reczones.cc @@ -78,27 +78,7 @@ static void convertServersForAD(const std::string& zone, const std::string& inpu } } if (verbose) { - if (!g_slogStructured) { - g_log << Logger::Info << "Redirecting queries for zone '" << zone << "' "; - if (authDomain.d_rdForward) { - g_log << "with recursion "; - } - g_log << "to: "; - bool first = true; - for (const auto& address : addresses) { - if (!first) { - g_log << ", "; - } - else { - first = false; - } - g_log << address; - } - g_log << endl; - } - else { - log->info(Logr::Info, "Redirecting queries", "zone", Logging::Loggable(zone), "recursion", Logging::Loggable(authDomain.d_rdForward), "addresses", Logging::IterLoggable(addresses.begin(), addresses.end())); - } + log->info(Logr::Info, "Redirecting queries", "zone", Logging::Loggable(zone), "recursion", Logging::Loggable(authDomain.d_rdForward), "addresses", Logging::IterLoggable(addresses.begin(), addresses.end())); } }