From: Remi Gacogne Date: Thu, 15 Jan 2026 15:26:01 +0000 (+0100) Subject: dnsdist: Ensure we always have a structured logging subsystem set X-Git-Tag: rec-5.4.0-beta1~33^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c8e705a28865fe9e89399f1ff880630c4542d16e;p=thirdparty%2Fpdns.git dnsdist: Ensure we always have a structured logging subsystem set Signed-off-by: Remi Gacogne --- diff --git a/pdns/dnsdistdist/bpf-filter.cc b/pdns/dnsdistdist/bpf-filter.cc index f4f64d0ae4..b279dbf5ce 100644 --- a/pdns/dnsdistdist/bpf-filter.cc +++ b/pdns/dnsdistdist/bpf-filter.cc @@ -367,7 +367,7 @@ BPFFilter::BPFFilter(std::unordered_map& configs, /* Check if the current soft memlock limit is at least the limit */ if (old_limit.rlim_cur < new_limit_size) { SLOG(infolog("The current limit of locked memory (soft: %d, hard: %d) is too low for eBPF, trying to raise it to %d", old_limit.rlim_cur, old_limit.rlim_max, new_limit_size), - dnsdist::logging::getTopLogger()->info("The current limit of locked memory is too low for eBPF, trying to raise it", "soft", Logging::Loggable(old_limit.rlim_cur), "hard", Logging::Loggable(old_limit.rlim_max), "target", Logging::Loggable(new_limit_size))); + dnsdist::logging::getTopLogger("bpf")->info("The current limit of locked memory is too low for eBPF, trying to raise it", "soft", Logging::Loggable(old_limit.rlim_cur), "hard", Logging::Loggable(old_limit.rlim_max), "target", Logging::Loggable(new_limit_size))); struct rlimit new_limit{}; new_limit.rlim_cur = new_limit_size; @@ -375,7 +375,7 @@ BPFFilter::BPFFilter(std::unordered_map& configs, if (setrlimit(RLIMIT_MEMLOCK, &new_limit) != 0) { SLOG(warnlog("Unable to raise the maximum amount of locked memory for eBPF from %d to %d, consider raising RLIMIT_MEMLOCK or setting LimitMEMLOCK in the systemd unit: %d", old_limit.rlim_cur, new_limit.rlim_cur, stringerror()), - dnsdist::logging::getTopLogger()->info(Logr::Warning, "Unable to raise the maximum amount of locked memory for eBPF, consider raising RLIMIT_MEMLOCK or setting LimitMEMLOCK in the systemd unit", "current", Logging::Loggable(old_limit.rlim_cur), "target", Logging::Loggable(new_limit_size))); + dnsdist::logging::getTopLogger("bpf")->info(Logr::Warning, "Unable to raise the maximum amount of locked memory for eBPF, consider raising RLIMIT_MEMLOCK or setting LimitMEMLOCK in the systemd unit", "current", Logging::Loggable(old_limit.rlim_cur), "target", Logging::Loggable(new_limit_size))); } } diff --git a/pdns/dnsdistdist/dnscrypt.cc b/pdns/dnsdistdist/dnscrypt.cc index 95892c14ec..40823e2c96 100644 --- a/pdns/dnsdistdist/dnscrypt.cc +++ b/pdns/dnsdistdist/dnscrypt.cc @@ -496,7 +496,7 @@ void DNSCryptQuery::getDecrypted(bool tcp, PacketBuffer& packet) #ifdef DNSCRYPT_STRICT_PADDING_LENGTH if (tcp && ((packet.size() - sizeof(DNSCryptQueryHeader)) % DNSCRYPT_PADDED_BLOCK_SIZE) != 0) { VERBOSESLOG(infolog("Dropping encrypted query with invalid size of %d (should be a multiple of %d)", (packet.size() - sizeof(DNSCryptQueryHeader)), DNSCRYPT_PADDED_BLOCK_SIZE), - dnsdist::logging::getTopLogger()->info("Dropping DNSCrypt-encrypted query with invalid size (should be a multiple of " DNSCRYPT_PADDED_BLOCK_SIZE, "dns.question.size", Logging::Loggable(packet.size() - sizeof(DNSCryptQueryHeader)))); + dnsdist::logging::getTopLogger("dnscrypt")->info("Dropping DNSCrypt-encrypted query with invalid size (should be a multiple of " DNSCRYPT_PADDED_BLOCK_SIZE, "dns.question.size", Logging::Loggable(packet.size() - sizeof(DNSCryptQueryHeader)))); return; } #endif @@ -509,7 +509,7 @@ void DNSCryptQuery::getDecrypted(bool tcp, PacketBuffer& packet) int res = computeSharedKey(); if (res != 0) { VERBOSESLOG(infolog("Dropping encrypted query we can't compute the shared key for"), - dnsdist::logging::getTopLogger()->info("Dropping DNSCrypt-encrypted query we can't compute the shared key for")); + dnsdist::logging::getTopLogger("dnscrypt")->info("Dropping DNSCrypt-encrypted query we can't compute the shared key for")); return; } @@ -554,7 +554,7 @@ void DNSCryptQuery::getDecrypted(bool tcp, PacketBuffer& packet) if (res != 0) { VERBOSESLOG(infolog("Dropping encrypted query we can't decrypt"), - dnsdist::logging::getTopLogger()->error(Logr::Info, res, "Dropping DNSCrypt-encrypted query we couldn't decrypt")); + dnsdist::logging::getTopLogger("dnscrypt")->error(Logr::Info, res, "Dropping DNSCrypt-encrypted query we couldn't decrypt")); return; } @@ -562,7 +562,7 @@ void DNSCryptQuery::getDecrypted(bool tcp, PacketBuffer& packet) uint16_t pos = decryptedQueryLen; if (pos >= packet.size()) { VERBOSESLOG(infolog("Dropping encrypted query we can't decrypt (invalid position)"), - dnsdist::logging::getTopLogger()->info("Dropping DNSCrypt-encrypted we couldn't decrypt because of an invalid position", "position", Logging::Loggable(pos), "dns.question.size", Logging::Loggable(packet.size()))); + dnsdist::logging::getTopLogger("dnscrypt")->info("Dropping DNSCrypt-encrypted we couldn't decrypt because of an invalid position", "position", Logging::Loggable(pos), "dns.question.size", Logging::Loggable(packet.size()))); return; } @@ -574,7 +574,7 @@ void DNSCryptQuery::getDecrypted(bool tcp, PacketBuffer& packet) if (pos == 0 || packet.at(pos - 1) != 0x80) { VERBOSESLOG(infolog("Dropping encrypted query with invalid padding value"), - dnsdist::logging::getTopLogger()->info("Dropping DNSCrypt-encrypted query with invalid padding value")); + dnsdist::logging::getTopLogger("dnscrypt")->info("Dropping DNSCrypt-encrypted query with invalid padding value")); return; } @@ -585,7 +585,7 @@ void DNSCryptQuery::getDecrypted(bool tcp, PacketBuffer& packet) if (tcp && paddingLen > DNSCRYPT_MAX_TCP_PADDING_SIZE) { VERBOSESLOG(infolog("Dropping encrypted query with too long padding size"), - dnsdist::logging::getTopLogger()->info("Dropping DNSCrypt-encrypted query withtoo long padding size")); + dnsdist::logging::getTopLogger("dnscrypt")->info("Dropping DNSCrypt-encrypted query withtoo long padding size")); return; } @@ -897,7 +897,7 @@ bool generateDNSCryptCertificate(const std::string& providerPrivateKeyFile, uint } catch (const std::exception& e) { SLOG(errlog(e.what()), - dnsdist::logging::getTopLogger()->error(e.what(), "Error while generating DNSCrypt certificate")); + dnsdist::logging::getTopLogger("dnscrypt")->error(e.what(), "Error while generating DNSCrypt certificate")); } sodium_memzero(providerPrivateKey.data(), providerPrivateKey.size()); diff --git a/pdns/dnsdistdist/dnsdist-actions-factory.cc b/pdns/dnsdistdist/dnsdist-actions-factory.cc index d2753a5e7b..8fa0e6fc6f 100644 --- a/pdns/dnsdistdist/dnsdist-actions-factory.cc +++ b/pdns/dnsdistdist/dnsdist-actions-factory.cc @@ -1177,7 +1177,7 @@ public: if (!reopenLogFile()) { int savederrno = errno; SLOG(warnlog("Unable to open file '%s' for logging: %s", d_fname, stringerror(savederrno)), - dnsdist::logging::getTopLogger()->error(Logr::Warning, savederrno, "Unable to open file for logging", "path", Logging::Loggable(d_fname))); + dnsdist::logging::getTopLogger("LogAction::reload")->error(Logr::Warning, savederrno, "Unable to open file for logging", "path", Logging::Loggable(d_fname))); } } @@ -1271,7 +1271,7 @@ public: if (!reopenLogFile()) { int savederrno = errno; SLOG(warnlog("Unable to open file '%s' for logging: %s", d_fname, stringerror(savederrno)), - dnsdist::logging::getTopLogger()->error(Logr::Warning, savederrno, "Unable to open file for logging", "path", Logging::Loggable(d_fname))); + dnsdist::logging::getTopLogger("LogResponseAction::reload")->error(Logr::Warning, savederrno, "Unable to open file for logging", "path", Logging::Loggable(d_fname))); } } @@ -1524,17 +1524,17 @@ static void remoteLoggerQueueData(RemoteLoggerInterface& remoteLogger, const std break; case RemoteLoggerInterface::Result::PipeFull: { VERBOSESLOG(infolog("%s: %s", remoteLogger.name(), RemoteLoggerInterface::toErrorString(ret)), - dnsdist::logging::getTopLogger()->error(Logr::Info, RemoteLoggerInterface::toErrorString(ret), "Remote logger pipe full event", "remote_logger_name", Logging::Loggable(remoteLogger.name()))); + dnsdist::logging::getTopLogger("remote-logger")->error(Logr::Info, RemoteLoggerInterface::toErrorString(ret), "Remote logger pipe full event", "remote_logger_name", Logging::Loggable(remoteLogger.name()))); break; } case RemoteLoggerInterface::Result::TooLarge: { SLOG(warnlog("%s: %s", remoteLogger.name(), RemoteLoggerInterface::toErrorString(ret)), - dnsdist::logging::getTopLogger()->error(Logr::Warning, RemoteLoggerInterface::toErrorString(ret), "Remote logger too large event", "remote_logger_name", Logging::Loggable(remoteLogger.name()))); + dnsdist::logging::getTopLogger("remote-logger")->error(Logr::Warning, RemoteLoggerInterface::toErrorString(ret), "Remote logger too large event", "remote_logger_name", Logging::Loggable(remoteLogger.name()))); break; } case RemoteLoggerInterface::Result::OtherError: SLOG(warnlog("%s: %s", remoteLogger.name(), RemoteLoggerInterface::toErrorString(ret)), - dnsdist::logging::getTopLogger()->error(Logr::Warning, RemoteLoggerInterface::toErrorString(ret), "Remote logger error event", "remote_logger_name", Logging::Loggable(remoteLogger.name()))); + dnsdist::logging::getTopLogger("remote-logger")->error(Logr::Warning, RemoteLoggerInterface::toErrorString(ret), "Remote logger error event", "remote_logger_name", Logging::Loggable(remoteLogger.name()))); } } diff --git a/pdns/dnsdistdist/dnsdist-async.cc b/pdns/dnsdistdist/dnsdist-async.cc index 9cf8f9a8a3..8bd0caa46e 100644 --- a/pdns/dnsdistdist/dnsdist-async.cc +++ b/pdns/dnsdistdist/dnsdist-async.cc @@ -136,7 +136,7 @@ void AsynchronousHolder::mainThread(std::shared_ptr data) expiredEvents.pop_front(); if (!data->d_failOpen) { VERBOSESLOG(infolog("Asynchronous query %d has expired at %d.%d, notifying the sender", queryID, now.tv_sec, now.tv_usec), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Asynchronous query has expired, notifying the sender", "dns.question.id", Logging::Loggable(queryID))); + dnsdist::logging::getTopLogger("async-thread")->info(Logr::Info, "Asynchronous query has expired, notifying the sender", "dns.question.id", Logging::Loggable(queryID))); auto sender = query->getTCPQuerySender(); if (sender) { TCPResponse tresponse(std::move(query->query)); @@ -145,7 +145,7 @@ void AsynchronousHolder::mainThread(std::shared_ptr data) } else { VERBOSESLOG(infolog("Asynchronous query %d has expired at %d.%d, resuming", queryID, now.tv_sec, now.tv_usec), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Asynchronous query has expired, resuming", "dns.question.id", Logging::Loggable(queryID))); + dnsdist::logging::getTopLogger("async-thread")->info(Logr::Info, "Asynchronous query has expired, resuming", "dns.question.id", Logging::Loggable(queryID))); resumeQuery(std::move(query)); } } @@ -186,7 +186,7 @@ std::unique_ptr AsynchronousHolder::get(uint16_t asyncID, ui timeval now{}; gettimeofday(&now, nullptr); VERBOSESLOG(infolog("Asynchronous object %d not found at %d.%d", queryID, now.tv_sec, now.tv_usec), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Asynchronous object not found", "dnsdist.async.id", Logging::Loggable(asyncID), "dns.question.id", Logging::Loggable(queryID))); + dnsdist::logging::getTopLogger("async-holder")->info(Logr::Info, "Asynchronous object not found", "dnsdist.async.id", Logging::Loggable(asyncID), "dns.question.id", Logging::Loggable(queryID))); return nullptr; } @@ -242,7 +242,7 @@ static bool resumeResponse(std::unique_ptr&& response) } catch (const std::exception& e) { VERBOSESLOG(infolog("Got exception while resuming cross-protocol response: %s", e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Info, e.what(), "Got exception while resuming cross-protocol response")); + dnsdist::logging::getTopLogger("async-holder")->error(Logr::Info, e.what(), "Got exception while resuming cross-protocol response")); return false; } @@ -273,7 +273,7 @@ void handleQueuedAsynchronousEvents() } if (query && !resumeQuery(std::move(query))) { VERBOSESLOG(infolog("Unable to resume asynchronous query event"), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Unable to resume asynchronous query event")); + dnsdist::logging::getTopLogger("async-holder")->info(Logr::Info, "Unable to resume asynchronous query event")); } } } @@ -332,14 +332,14 @@ bool resumeQuery(std::unique_ptr&& query) } catch (const std::exception& e) { VERBOSESLOG(infolog("Got exception while resuming cross-protocol self-answered query: %s", e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Info, e.what(), "Got exception while resuming cross-protocol self-answered query")); + dnsdist::logging::getTopLogger("async-holder")->error(Logr::Info, e.what(), "Got exception while resuming cross-protocol self-answered query")); return false; } } if (result == ProcessQueryResult::Asynchronous) { /* nope */ SLOG(errlog("processQueryAfterRules returned 'asynchronous' while trying to resume an already asynchronous query"), - dnsdist::logging::getTopLogger()->info(Logr::Info, "processQueryAfterRules returned 'asynchronous' while trying to resume an already asynchronous query")); + dnsdist::logging::getTopLogger("async-holder")->info(Logr::Info, "processQueryAfterRules returned 'asynchronous' while trying to resume an already asynchronous query")); return false; } diff --git a/pdns/dnsdistdist/dnsdist-backend.cc b/pdns/dnsdistdist/dnsdist-backend.cc index a0aa1bd75c..9e5f2c075e 100644 --- a/pdns/dnsdistdist/dnsdist-backend.cc +++ b/pdns/dnsdistdist/dnsdist-backend.cc @@ -260,7 +260,7 @@ void DownstreamState::hash() { const auto hashPerturbation = dnsdist::configuration::getImmutableConfiguration().d_hashPerturbation; VERBOSESLOG(infolog("Computing hashes for id=%s and weight=%d, hash_perturbation=%d", *d_config.id, d_config.d_weight, hashPerturbation), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Computing hashes for backend", "backend.id", Logging::Loggable(*d_config.id), "backend.weight", Logging::Loggable(d_config.d_weight), "backend.hash_perturbation", Logging::Loggable(hashPerturbation))); + dnsdist::logging::getTopLogger("backend")->info(Logr::Info, "Computing hashes for backend", "backend.id", Logging::Loggable(*d_config.id), "backend.weight", Logging::Loggable(d_config.d_weight), "backend.hash_perturbation", Logging::Loggable(hashPerturbation))); auto weight = d_config.d_weight; auto idStr = boost::str(boost::format("%s") % *d_config.id); @@ -1008,7 +1008,7 @@ bool DownstreamState::parseSourceParameter(const std::string& source, Downstream } SLOG(warnlog("Dismissing source %s because '%s' is not a valid interface name", source, config.sourceItfName), - dnsdist::logging::getTopLogger()->info(Logr::Warning, "Dismissing source because the interface name is not valid", "backend.name", Logging::Loggable(config.name), "backend.address", Logging::Loggable(config.remote), "source.address", Logging::Loggable(source), "source.interface", Logging::Loggable(config.sourceItfName))); + dnsdist::logging::getTopLogger("backend")->info(Logr::Warning, "Dismissing source because the interface name is not valid", "backend.name", Logging::Loggable(config.name), "backend.address", Logging::Loggable(config.remote), "source.address", Logging::Loggable(source), "source.interface", Logging::Loggable(config.sourceItfName))); return false; } @@ -1043,7 +1043,7 @@ unsigned int DownstreamState::getQPSLimit() const [[nodiscard]] std::shared_ptr DownstreamState::getLogger() const { - return dnsdist::logging::getTopLogger()->withName("backend")->withValues("backend.name", Logging::Loggable(getName()), "backend.address", Logging::Loggable(d_config.remote), "backend.protocol", Logging::Loggable(getProtocol())); + return dnsdist::logging::getTopLogger("backend")->withValues("backend.name", Logging::Loggable(getName()), "backend.address", Logging::Loggable(d_config.remote), "backend.protocol", Logging::Loggable(getProtocol())); } size_t ServerPool::countServers(bool upOnly) const diff --git a/pdns/dnsdistdist/dnsdist-carbon.cc b/pdns/dnsdistdist/dnsdist-carbon.cc index 0364eeea19..3bad273103 100644 --- a/pdns/dnsdistdist/dnsdist-carbon.cc +++ b/pdns/dnsdistdist/dnsdist-carbon.cc @@ -307,7 +307,7 @@ static void carbonHandler(const Carbon::Endpoint& endpoint) { setThreadName("dnsdist/carbon"); const auto ourName = endpoint.getOurName(); - auto logger = dnsdist::logging::getTopLogger()->withName("carbon-exporter")->withValues("server.address", Logging::Loggable(endpoint.server), "dnsdist.carbon.our_name", Logging::Loggable(ourName)); + auto logger = dnsdist::logging::getTopLogger("carbon-exporter")->withValues("server.address", Logging::Loggable(endpoint.server), "dnsdist.carbon.our_name", Logging::Loggable(ourName)); const auto intervalUSec = endpoint.interval * 1000 * 1000; /* maximum interval between two attempts is 10 minutes */ diff --git a/pdns/dnsdistdist/dnsdist-concurrent-connections.cc b/pdns/dnsdistdist/dnsdist-concurrent-connections.cc index 935c4fa8d9..eeb277081e 100644 --- a/pdns/dnsdistdist/dnsdist-concurrent-connections.cc +++ b/pdns/dnsdistdist/dnsdist-concurrent-connections.cc @@ -188,18 +188,18 @@ IncomingConcurrentTCPConnectionsManager::NewConnectionResult IncomingConcurrentT auto checkConnectionAllowed = [now, from, maxConnsPerClient, threshold, tcpRate, tlsNewRate, tlsResumedRate, interval, isTLS, &immutable](const ClientEntry& entry) { if (entry.d_bannedUntil != 0 && entry.d_bannedUntil >= now) { VERBOSESLOG(infolog("Refusing TCP connection from %s: banned", from.toStringWithPort()), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Refusing TCP connection", "reason", Logging::Loggable("banned"), "client.address", Logging::Loggable(from))); + dnsdist::logging::getTopLogger("concurrent-tcp-connections-manager")->info(Logr::Info, "Refusing TCP connection", "reason", Logging::Loggable("banned"), "client.address", Logging::Loggable(from))); return NewConnectionResult::Denied; } if (maxConnsPerClient > 0 && entry.d_concurrentConnections >= maxConnsPerClient) { VERBOSESLOG(infolog("Refusing TCP connection from %s: too many connections", from.toStringWithPort()), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Refusing TCP connection", "reason", Logging::Loggable("too many connections"), "client.address", Logging::Loggable(from))); + dnsdist::logging::getTopLogger("concurrent-tcp-connections-manager")->info(Logr::Info, "Refusing TCP connection", "reason", Logging::Loggable("too many connections"), "client.address", Logging::Loggable(from))); return NewConnectionResult::Denied; } if (!checkTCPConnectionsRate(entry.d_activity, now, tcpRate, tlsNewRate, tlsResumedRate, interval, isTLS)) { entry.d_bannedUntil = now + immutable.d_tcpBanDurationForExceedingTCPTLSRate; VERBOSESLOG(infolog("Banning TCP connections from %s for %d seconds: too many new TCP/TLS connections per second", from.toStringWithPort(), immutable.d_tcpBanDurationForExceedingTCPTLSRate), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Banning TCP connections from this client", "reason", Logging::Loggable("too many new TCP/TLS connections per second"), "client.address", Logging::Loggable(from), "duration-seconds", Logging::Loggable(immutable.d_tcpBanDurationForExceedingTCPTLSRate))); + dnsdist::logging::getTopLogger("concurrent-tcp-connections-manager")->info(Logr::Info, "Banning TCP connections from this client", "reason", Logging::Loggable("too many new TCP/TLS connections per second"), "client.address", Logging::Loggable(from), "duration-seconds", Logging::Loggable(immutable.d_tcpBanDurationForExceedingTCPTLSRate))); return NewConnectionResult::Denied; } @@ -212,7 +212,7 @@ IncomingConcurrentTCPConnectionsManager::NewConnectionResult IncomingConcurrentT return NewConnectionResult::Allowed; } VERBOSESLOG(infolog("Restricting TCP connection from %s: nearly reaching the maximum number of concurrent TCP connections", from.toStringWithPort()), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Restricting TCP connections from this client", "reason", Logging::Loggable("nearly reaching the maximum number of concurrent TCP connections"), "client.address", Logging::Loggable(from))); + dnsdist::logging::getTopLogger("concurrent-tcp-connections-manager")->info(Logr::Info, "Restricting TCP connections from this client", "reason", Logging::Loggable("nearly reaching the maximum number of concurrent TCP connections"), "client.address", Logging::Loggable(from))); return NewConnectionResult::Restricted; }; @@ -278,7 +278,7 @@ void IncomingConcurrentTCPConnectionsManager::banClientFor(const ComboAddress& f }); } VERBOSESLOG(infolog("Banned TCP client %s for %d seconds", from.toStringWithPort(), seconds), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Banned TCP connections from this client", "client.address", Logging::Loggable(from), "duration-seconds", Logging::Loggable(seconds))); + dnsdist::logging::getTopLogger("concurrent-tcp-connections-manager")->info(Logr::Info, "Banned TCP connections from this client", "client.address", Logging::Loggable(from), "duration-seconds", Logging::Loggable(seconds))); } static void editEntryIfPresent(const ComboAddress& from, const std::function& callback) diff --git a/pdns/dnsdistdist/dnsdist-configuration-yaml.cc b/pdns/dnsdistdist/dnsdist-configuration-yaml.cc index 5ca65eed1f..16787b48a4 100644 --- a/pdns/dnsdistdist/dnsdist-configuration-yaml.cc +++ b/pdns/dnsdistdist/dnsdist-configuration-yaml.cc @@ -1133,7 +1133,7 @@ bool loadConfigurationFromFile(const std::string& fileName, [[maybe_unused]] boo // Rust code would be quite cumbersome so for now let's settle for this s_inConfigCheckMode.store(configCheck); s_inClientMode.store(isClient); - auto logger = dnsdist::logging::getTopLogger()->withName("yaml-configuration")->withValues("path", Logging::Loggable(fileName), "client_mode", Logging::Loggable(isClient), "configuration_check", Logging::Loggable(configCheck)); + auto logger = dnsdist::logging::getTopLogger("yaml-configuration")->withValues("path", Logging::Loggable(fileName), "client_mode", Logging::Loggable(isClient), "configuration_check", Logging::Loggable(configCheck)); Context context{ .logger = logger, }; diff --git a/pdns/dnsdistdist/dnsdist-console.cc b/pdns/dnsdistdist/dnsdist-console.cc index 9034bb3c57..df452b0f0f 100644 --- a/pdns/dnsdistdist/dnsdist-console.cc +++ b/pdns/dnsdistdist/dnsdist-console.cc @@ -322,7 +322,7 @@ void doClient(const std::string& command) } #else SLOG(errlog("Client mode requested but libedit support is not available"), - dnsdist::logging::getTopLogger()->info(Logr::Error, "Client mode requested but libedit support is not available")); + dnsdist::logging::getTopLogger("console-client")->info(Logr::Error, "Client mode requested but libedit support is not available")); #endif /* HAVE_LIBEDIT */ } @@ -640,7 +640,7 @@ void controlThread(Socket&& acceptFD) { setThreadName("dnsdist/control"); const ComboAddress local = dnsdist::configuration::getCurrentRuntimeConfiguration().d_consoleServerAddress; - auto logger = dnsdist::logging::getTopLogger()->withName("console-server")->withValues("network.local.address", Logging::Loggable(local)); + auto logger = dnsdist::logging::getTopLogger("console-server")->withValues("network.local.address", Logging::Loggable(local)); try { s_connManager.setMaxConcurrentConnections(dnsdist::configuration::getImmutableConfiguration().d_consoleMaxConcurrentConnections); @@ -673,7 +673,7 @@ void controlThread(Socket&& acceptFD) try { ConsoleConnection conn(client, std::move(socket)); - auto connLogger = dnsdist::logging::getTopLogger()->withName("console-connection")->withValues("client.address", Logging::Loggable(client)); + auto connLogger = dnsdist::logging::getTopLogger("console-connection")->withValues("client.address", Logging::Loggable(client)); if (runtimeConfig.d_logConsoleConnections) { SLOG(warnlog("Got control connection from %s", client.toStringWithPort()), connLogger->info(Logr::Info, "Control connection opened")); diff --git a/pdns/dnsdistdist/dnsdist-discovery.cc b/pdns/dnsdistdist/dnsdist-discovery.cc index da1904c100..6c6321bd2b 100644 --- a/pdns/dnsdistdist/dnsdist-discovery.cc +++ b/pdns/dnsdistdist/dnsdist-discovery.cc @@ -519,7 +519,7 @@ bool ServiceDiscovery::tryToUpgradeBackend(const Logr::Logger& logger, const Upg void ServiceDiscovery::worker() { setThreadName("dnsdist/discove"); - auto logger = dnsdist::logging::getTopLogger()->withName("service-discovery"); + auto logger = dnsdist::logging::getTopLogger("service-discovery"); while (true) { dnsdist::configuration::refreshLocalRuntimeConfiguration(); diff --git a/pdns/dnsdistdist/dnsdist-dnscrypt.cc b/pdns/dnsdistdist/dnsdist-dnscrypt.cc index ac1196fde4..e143189dfd 100644 --- a/pdns/dnsdistdist/dnsdist-dnscrypt.cc +++ b/pdns/dnsdistdist/dnsdist-dnscrypt.cc @@ -31,7 +31,7 @@ bool handleDNSCryptQuery(PacketBuffer& packet, DNSCryptQuery& query, bool tcp, t if (!query.isValid()) { VERBOSESLOG(infolog("Dropping DNSCrypt invalid query"), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Dropping DNSCrypt invalid query")); + dnsdist::logging::getTopLogger("dnscrypt")->info(Logr::Info, "Dropping DNSCrypt invalid query")); return false; } diff --git a/pdns/dnsdistdist/dnsdist-dynblocks.cc b/pdns/dnsdistdist/dnsdist-dynblocks.cc index 6c0122dbea..a9d86d9a2b 100644 --- a/pdns/dnsdistdist/dnsdist-dynblocks.cc +++ b/pdns/dnsdistdist/dnsdist-dynblocks.cc @@ -263,13 +263,13 @@ bool addOrRefreshBlock(ClientAddressDynamicRules& blocks, const timespec& now, c } catch (const std::exception& e) { VERBOSESLOG(infolog("Unable to insert eBPF dynamic block for %s, falling back to regular dynamic block: %s", requestor.toString(), e.what()), - dnsdist::logging::getTopLogger()->withName("dynamic-rules")->error(Logr::Info, e.what(), "Unable to insert eBPF dynamic block, falling back to regular dynamic block", "client.address", Logging::Loggable(requestor))); + dnsdist::logging::getTopLogger("dynamic-rules")->error(Logr::Info, e.what(), "Unable to insert eBPF dynamic block, falling back to regular dynamic block", "client.address", Logging::Loggable(requestor))); } } if (!beQuiet) { SLOG(warnlog("Inserting %s%sdynamic block for %s for %d seconds: %s", dblock.warning ? "(warning) " : "", bpf ? "eBPF " : "", requestor.toString(), dblock.until.tv_sec - now.tv_sec, dblock.reason), - dnsdist::logging::getTopLogger()->withName("dynamic-rules")->info(Logr::Warning, "Inserting dynamic rule", "dynamic_rule.warning_rule", Logging::Loggable(dblock.warning), "client.address", Logging::Loggable(requestor), "dynamic_rule.use_bpf", Logging::Loggable(bpf), "dynamic_rule.reason", Logging::Loggable(dblock.reason), "dynamic_rule.duration", Logging::Loggable(dblock.until.tv_sec - now.tv_sec))); + dnsdist::logging::getTopLogger("dynamic-rules")->info(Logr::Warning, "Inserting dynamic rule", "dynamic_rule.warning_rule", Logging::Loggable(dblock.warning), "client.address", Logging::Loggable(requestor), "dynamic_rule.use_bpf", Logging::Loggable(bpf), "dynamic_rule.reason", Logging::Loggable(dblock.reason), "dynamic_rule.duration", Logging::Loggable(dblock.until.tv_sec - now.tv_sec))); } } @@ -311,7 +311,7 @@ bool addOrRefreshBlockSMT(SuffixDynamicRules& blocks, const timespec& now, DynBl if (!beQuiet && (got == nullptr || expired)) { SLOG(warnlog("Inserting dynamic block for %s for %d seconds: %s", dblock.domain, dblock.until.tv_sec - now.tv_sec, dblock.reason), - dnsdist::logging::getTopLogger()->withName("dynamic-rules")->info(Logr::Warning, "Inserting dynamic rule", "dynamic_rule.warning_rule", Logging::Loggable(false), "dns.query.name", Logging::Loggable(dblock.domain), "dynamic_rule.use_bpf", Logging::Loggable(false), "dynamic_rule.reason", Logging::Loggable(dblock.reason), "dynamic_rule.duration", Logging::Loggable(dblock.until.tv_sec - now.tv_sec))); + dnsdist::logging::getTopLogger("dynamic-rules")->info(Logr::Warning, "Inserting dynamic rule", "dynamic_rule.warning_rule", Logging::Loggable(false), "dns.query.name", Logging::Loggable(dblock.domain), "dynamic_rule.use_bpf", Logging::Loggable(false), "dynamic_rule.reason", Logging::Loggable(dblock.reason), "dynamic_rule.duration", Logging::Loggable(dblock.until.tv_sec - now.tv_sec))); } auto domain = dblock.domain; @@ -346,7 +346,7 @@ void DynBlockRulesGroup::addOrRefreshBlock(std::optionalwithName("dynamic-rules")->error(Logr::Warning, exp.what(), "Error calling the Lua hook after a dynamic rule insertion")); + dnsdist::logging::getTopLogger("dynamic-rules")->error(Logr::Warning, exp.what(), "Error calling the Lua hook after a dynamic rule insertion")); } } } @@ -371,7 +371,7 @@ void DynBlockRulesGroup::addOrRefreshBlockSMT(SuffixDynamicRules& blocks, const } catch (const std::exception& exp) { SLOG(warnlog("Error calling the Lua hook after a dynamic block insertion: %s", exp.what()), - dnsdist::logging::getTopLogger()->withName("dynamic-rules")->error(Logr::Warning, exp.what(), "Error calling the Lua hook after a suffix-based dynamic rule insertion")); + dnsdist::logging::getTopLogger("dynamic-rules")->error(Logr::Warning, exp.what(), "Error calling the Lua hook after a suffix-based dynamic rule insertion")); } } } @@ -511,7 +511,7 @@ void DynBlockMaintenance::purgeExpired(const struct timespec& now) } catch (const std::exception& e) { VERBOSESLOG(infolog("Error while getting block count before removing eBPF dynamic block for %s: %s", entry.first.toString(), e.what()), - dnsdist::logging::getTopLogger()->withName("dynamic-rules")->error(Logr::Info, e.what(), "Error while getting block count before removing eBPF dynamic block", "dynamic_rule.key", Logging::Loggable(entry.first))); + dnsdist::logging::getTopLogger("dynamic-rules")->error(Logr::Info, e.what(), "Error while getting block count before removing eBPF dynamic block", "dynamic_rule.key", Logging::Loggable(entry.first))); } try { @@ -519,7 +519,7 @@ void DynBlockMaintenance::purgeExpired(const struct timespec& now) } catch (const std::exception& e) { VERBOSESLOG(infolog("Error while removing eBPF dynamic block for %s: %s", entry.first.toString(), e.what()), - dnsdist::logging::getTopLogger()->withName("dynamic-rules")->error(Logr::Info, e.what(), "Error while removing eBPF dynamic block", "dynamic_rule.key", Logging::Loggable(entry.first))); + dnsdist::logging::getTopLogger("dynamic-rules")->error(Logr::Info, e.what(), "Error while removing eBPF dynamic block", "dynamic_rule.key", Logging::Loggable(entry.first))); } } } @@ -827,11 +827,11 @@ void DynBlockMaintenance::run() } catch (const std::exception& e) { SLOG(warnlog("Error in the dynamic block maintenance thread: %s", e.what()), - dnsdist::logging::getTopLogger()->withName("dynamic-rules")->error(Logr::Warning, e.what(), "Error in the dynamic block maintenance thread")); + dnsdist::logging::getTopLogger("dynamic-rules")->error(Logr::Warning, e.what(), "Error in the dynamic block maintenance thread")); } catch (...) { VERBOSESLOG(infolog("Unhandled error in the dynamic block maintenance thread"), - dnsdist::logging::getTopLogger()->withName("dynamic-rules")->info(Logr::Info, "Unhandled error in the dynamic block maintenance thread")); + dnsdist::logging::getTopLogger("dynamic-rules")->info(Logr::Info, "Unhandled error in the dynamic block maintenance thread")); } } } diff --git a/pdns/dnsdistdist/dnsdist-healthchecks.cc b/pdns/dnsdistdist/dnsdist-healthchecks.cc index b0ed0999d6..8dcc175dc9 100644 --- a/pdns/dnsdistdist/dnsdist-healthchecks.cc +++ b/pdns/dnsdistdist/dnsdist-healthchecks.cc @@ -74,7 +74,7 @@ static void updateLatencyMetrics(DownstreamState& downstream, int elapsed /* mic static std::shared_ptr getLoggerFromData(const std::shared_ptr& data) { const auto& downstream = data->d_ds; - return dnsdist::logging::getTopLogger()->withName("backend-health-check")->withValues("health_check.proto", Logging::Loggable(downstream->doHealthcheckOverTCP() ? (data->d_tcpHandler->isTLS() ? "DoT" : "tcp") : "udp"), "backend.name", Logging::Loggable(downstream->getName()), "backend.address", Logging::Loggable(downstream->d_config.remote), "dns.query.id", Logging::Loggable(data->d_queryID), "dns.query.name", Logging::Loggable(data->d_checkName), "dns.query.type", Logging::Loggable(data->d_checkType), "dns.query.class", Logging::Loggable(data->d_checkClass)); + return dnsdist::logging::getTopLogger("backend-health-check")->withValues("health_check.proto", Logging::Loggable(downstream->doHealthcheckOverTCP() ? (data->d_tcpHandler->isTLS() ? "DoT" : "tcp") : "udp"), "backend.name", Logging::Loggable(downstream->getName()), "backend.address", Logging::Loggable(downstream->d_config.remote), "dns.query.id", Logging::Loggable(data->d_queryID), "dns.query.name", Logging::Loggable(data->d_checkName), "dns.query.type", Logging::Loggable(data->d_checkType), "dns.query.class", Logging::Loggable(data->d_checkClass)); } static bool handleResponse(std::shared_ptr& data) @@ -356,7 +356,7 @@ bool queueHealthCheck(std::unique_ptr& mplexer, const std::shared const auto verboseHealthChecks = dnsdist::configuration::getCurrentRuntimeConfiguration().d_verboseHealthChecks; std::shared_ptr logger; if (verboseHealthChecks) { - logger = dnsdist::logging::getTopLogger()->withName("backend-health-check")->withValues("backend.name", Logging::Loggable(downstream->getName()), "backend.address", Logging::Loggable(downstream->d_config.remote)); + logger = dnsdist::logging::getTopLogger("backend-health-check")->withValues("backend.name", Logging::Loggable(downstream->getName()), "backend.address", Logging::Loggable(downstream->d_config.remote)); } try { @@ -515,9 +515,9 @@ bool queueHealthCheck(std::unique_ptr& mplexer, const std::shared void handleQueuedHealthChecks(FDMultiplexer& mplexer, bool initial) { const auto verboseHealthChecks = dnsdist::configuration::getCurrentRuntimeConfiguration().d_verboseHealthChecks; - std::shared_ptr logger; + std::shared_ptr logger; if (verboseHealthChecks) { - logger = dnsdist::logging::getTopLogger()->withName("backend-health-check"); + logger = dnsdist::logging::getTopLogger("backend-health-check"); } while (mplexer.getWatchedFDCount(false) > 0 || mplexer.getWatchedFDCount(true) > 0) { diff --git a/pdns/dnsdistdist/dnsdist-idstate.cc b/pdns/dnsdistdist/dnsdist-idstate.cc index 9855dfe898..f9e21983be 100644 --- a/pdns/dnsdistdist/dnsdist-idstate.cc +++ b/pdns/dnsdistdist/dnsdist-idstate.cc @@ -167,7 +167,7 @@ std::optional InternalQueryState::getRules std::shared_ptr InternalQueryState::getLogger(std::shared_ptr parent) const { if (!parent) { - parent = dnsdist::logging::getTopLogger(); + parent = dnsdist::logging::getTopLogger("query-processing"); } auto logger = parent->withValues("dns.question.name", Logging::Loggable(this->qname), "dns.question.type", Logging::Loggable(this->qtype), "dns.question.class", Logging::Loggable(this->qclass), "source.address", Logging::Loggable(this->origRemote), "destination.address", Logging::Loggable(this->origDest), "proto", Logging::Loggable(this->protocol), "dns.question.id", Logging::Loggable(ntohs(this->origID)), "dns.question.flags", Logging::Loggable(this->origFlags)); return logger; diff --git a/pdns/dnsdistdist/dnsdist-kvs.cc b/pdns/dnsdistdist/dnsdist-kvs.cc index 465595dbe2..ff2b1a0af3 100644 --- a/pdns/dnsdistdist/dnsdist-kvs.cc +++ b/pdns/dnsdistdist/dnsdist-kvs.cc @@ -83,7 +83,7 @@ std::vector KeyValueLookupKeySuffix::getKeys(const DNSName& qname) #ifdef HAVE_LMDB std::shared_ptr LMDBKVStore::getLogger() const { - return dnsdist::logging::getTopLogger()->withName("lmdb-key-value-store")->withValues("path", Logging::Loggable(d_fname), "database", Logging::Loggable(d_dbName)); + return dnsdist::logging::getTopLogger("lmdb-key-value-store")->withValues("path", Logging::Loggable(d_fname), "database", Logging::Loggable(d_dbName)); } bool LMDBKVStore::getValue(const std::string& key, std::string& value) @@ -181,7 +181,7 @@ bool LMDBKVStore::getRangeValue(const std::string& key, std::string& value) #ifdef HAVE_CDB std::shared_ptr CDBKVStore::getLogger() const { - return dnsdist::logging::getTopLogger()->withName("cdb-key-value-store")->withValues("path", Logging::Loggable(d_fname)); + return dnsdist::logging::getTopLogger("cdb-key-value-store")->withValues("path", Logging::Loggable(d_fname)); } CDBKVStore::CDBKVStore(const std::string& fname, time_t refreshDelay): d_fname(fname), d_refreshDelay(refreshDelay) diff --git a/pdns/dnsdistdist/dnsdist-lbpolicies.cc b/pdns/dnsdistdist/dnsdist-lbpolicies.cc index 35975f9ecb..8e2b3eec5e 100644 --- a/pdns/dnsdistdist/dnsdist-lbpolicies.cc +++ b/pdns/dnsdistdist/dnsdist-lbpolicies.cc @@ -327,7 +327,7 @@ const ServerPool& createPoolIfNotExists(const string& poolName) if (!poolName.empty()) { VERBOSESLOG(infolog("Creating pool %s", poolName), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Creating a new pool of backends", "pool", Logging::Loggable(poolName))); + dnsdist::logging::getTopLogger("pool")->info(Logr::Info, "Creating a new pool of backends", "pool", Logging::Loggable(poolName))); } dnsdist::configuration::updateRuntimeConfiguration([&poolName](dnsdist::configuration::RuntimeConfiguration& config) { @@ -345,10 +345,10 @@ void setPoolPolicy(const string& poolName, std::shared_ptr policy) { if (!poolName.empty()) { VERBOSESLOG(infolog("Setting pool %s server selection policy to %s", poolName, policy->getName()), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Setting pool server selection policy", "pool", Logging::Loggable(poolName), "policy", Logging::Loggable(policy->getName()))); + dnsdist::logging::getTopLogger("pool")->info(Logr::Info, "Setting pool server selection policy", "pool", Logging::Loggable(poolName), "policy", Logging::Loggable(policy->getName()))); } else { VERBOSESLOG(infolog("Setting default pool server selection policy to %s", policy->getName()), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Setting pool server selection policy", "pool", Logging::Loggable(poolName), "policy", Logging::Loggable(policy->getName()))); + dnsdist::logging::getTopLogger("pool")->info(Logr::Info, "Setting pool server selection policy", "pool", Logging::Loggable(poolName), "policy", Logging::Loggable(policy->getName()))); } @@ -362,10 +362,10 @@ void addServerToPool(const string& poolName, std::shared_ptr se { if (!poolName.empty()) { VERBOSESLOG(infolog("Adding server to pool %s", poolName), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Adding server to pool", "pool", Logging::Loggable(poolName))); + dnsdist::logging::getTopLogger("pool")->info(Logr::Info, "Adding server to pool", "pool", Logging::Loggable(poolName))); } else { VERBOSESLOG(infolog("Adding server to default pool"), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Adding server to pool", "pool", Logging::Loggable(poolName))); + dnsdist::logging::getTopLogger("pool")->info(Logr::Info, "Adding server to pool", "pool", Logging::Loggable(poolName))); } dnsdist::configuration::updateRuntimeConfiguration([&poolName, &server](dnsdist::configuration::RuntimeConfiguration& config) { @@ -378,11 +378,11 @@ void removeServerFromPool(const string& poolName, std::shared_ptrinfo(Logr::Info, "Removing server from pool", "pool", Logging::Loggable(poolName))); + dnsdist::logging::getTopLogger("pool")->info(Logr::Info, "Removing server from pool", "pool", Logging::Loggable(poolName))); } else { VERBOSESLOG(infolog("Removing server from default pool"), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Removing server from pool", "pool", Logging::Loggable(poolName))); + dnsdist::logging::getTopLogger("pool")->info(Logr::Info, "Removing server from pool", "pool", Logging::Loggable(poolName))); } dnsdist::configuration::updateRuntimeConfiguration([&poolName, &server](dnsdist::configuration::RuntimeConfiguration& config) { diff --git a/pdns/dnsdistdist/dnsdist-logging.cc b/pdns/dnsdistdist/dnsdist-logging.cc index ce6237395f..5b007a523e 100644 --- a/pdns/dnsdistdist/dnsdist-logging.cc +++ b/pdns/dnsdistdist/dnsdist-logging.cc @@ -213,14 +213,14 @@ void setup(const std::string& backend) } } -std::shared_ptr getTopLogger() +std::shared_ptr getTopLogger(const std::string_view& subsystem) { auto topLogger = std::atomic_load_explicit(&s_topLogger, std::memory_order_acquire); if (!topLogger) { throw std::runtime_error("Trying to access the top-level logger before logging has been setup"); } - return topLogger; + return topLogger->withName(std::string(subsystem)); } bool doVerboseLogging() diff --git a/pdns/dnsdistdist/dnsdist-logging.hh b/pdns/dnsdistdist/dnsdist-logging.hh index 29a78b1775..bdcad23471 100644 --- a/pdns/dnsdistdist/dnsdist-logging.hh +++ b/pdns/dnsdistdist/dnsdist-logging.hh @@ -22,13 +22,14 @@ #include #include +#include #include "logging.hh" namespace dnsdist::logging { void setup(const std::string& backend); -std::shared_ptr getTopLogger(); +std::shared_ptr getTopLogger(const std::string_view& subsystem); bool doVerboseLogging(); bool doStructuredLogging(); } diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-dnscrypt.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-dnscrypt.cc index 28460c5e36..cb39a2eff3 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-dnscrypt.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-dnscrypt.cc @@ -119,7 +119,7 @@ void setupLuaBindingsDNSCrypt([[maybe_unused]] LuaContext& luaCtx, [[maybe_unuse } catch (const std::exception& e) { SLOG(errlog("Error generating a DNSCrypt certificate: %s", e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Error, e.what(), "Error generating a DNSCrypt certificate")); + dnsdist::logging::getTopLogger("lua")->error(Logr::Error, e.what(), "Error generating a DNSCrypt certificate")); g_outputBuffer = "Error generating a DNSCrypt certificate: " + string(e.what()) + "\n"; return false; } @@ -185,7 +185,7 @@ void setupLuaBindingsDNSCrypt([[maybe_unused]] LuaContext& luaCtx, [[maybe_unuse } catch (const std::exception& e) { SLOG(errlog("Error generating a DNSCrypt certificate: %s", e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Error, e.what(), "Error generating a DNSCrypt certificate")); + dnsdist::logging::getTopLogger("lua")->error(Logr::Error, e.what(), "Error generating a DNSCrypt certificate")); g_outputBuffer = "Error generating a DNSCrypt certificate: " + string(e.what()) + "\n"; } }); @@ -216,7 +216,7 @@ void setupLuaBindingsDNSCrypt([[maybe_unused]] LuaContext& luaCtx, [[maybe_unuse } catch (const std::exception& e) { SLOG(errlog("Error generating a DNSCrypt provider key: %s", e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Error, e.what(), "Error generating a DNSCrypt provider key")); + dnsdist::logging::getTopLogger("lua")->error(Logr::Error, e.what(), "Error generating a DNSCrypt provider key")); g_outputBuffer = "Error generating a DNSCrypt provider key: " + string(e.what()) + "\n"; } @@ -242,7 +242,7 @@ void setupLuaBindingsDNSCrypt([[maybe_unused]] LuaContext& luaCtx, [[maybe_unuse } catch (const std::exception& e) { SLOG(errlog("Error getting a DNSCrypt provider fingerprint: %s", e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Error, e.what(), "Error getting a DNSCrypt provider fingerprint")); + dnsdist::logging::getTopLogger("lua")->error(Logr::Error, e.what(), "Error getting a DNSCrypt provider fingerprint")); g_outputBuffer = "Error getting a DNSCrypt provider fingerprint: " + string(e.what()) + "\n"; } }); diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-network.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-network.cc index e782a19961..856158cfc7 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-network.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-network.cc @@ -38,7 +38,7 @@ void setupLuaBindingsNetwork(LuaContext& luaCtx, bool client) } catch (const std::exception& e) { SLOG(warnlog("Error connecting to network endpoint: %s", e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Error, e.what(), "Error connecting to network endpoint")); + dnsdist::logging::getTopLogger("newNetworkEndpoint")->error(Logr::Error, e.what(), "Error connecting to network endpoint")); } return std::shared_ptr(nullptr); }); diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc b/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc index f3b20115b7..b772a51161 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc @@ -91,7 +91,7 @@ void setupLuaBindingsPacketCache(LuaContext& luaCtx, bool client) if (maxEntries < settings.d_shardCount) { SLOG(warnlog("The number of entries (%d) in the packet cache is smaller than the number of shards (%d), decreasing the number of shards to %d", maxEntries, settings.d_shardCount, maxEntries), - dnsdist::logging::getTopLogger()->withName("configuration")->info(Logr::Warning, "The number of entries in the packet cache is smaller than the number of shards, decreasing the number of shards to the number of entries", "number_of_entries", Logging::Loggable(maxEntries), "number_of_shards", Logging::Loggable(settings.d_shardCount))); + dnsdist::logging::getTopLogger("configuration")->info(Logr::Warning, "The number of entries in the packet cache is smaller than the number of shards, decreasing the number of shards to the number of entries", "number_of_entries", Logging::Loggable(maxEntries), "number_of_shards", Logging::Loggable(settings.d_shardCount))); g_outputBuffer += "The number of entries (" + std::to_string(maxEntries) + " in the packet cache is smaller than the number of shards (" + std::to_string(settings.d_shardCount) + "), decreasing the number of shards to " + std::to_string(maxEntries); settings.d_shardCount = maxEntries; } diff --git a/pdns/dnsdistdist/dnsdist-lua-bindings.cc b/pdns/dnsdistdist/dnsdist-lua-bindings.cc index 953d80aeed..97c1a4a4d5 100644 --- a/pdns/dnsdistdist/dnsdist-lua-bindings.cc +++ b/pdns/dnsdistdist/dnsdist-lua-bindings.cc @@ -39,19 +39,19 @@ void setupLuaBindingsLogging(LuaContext& luaCtx) { luaCtx.writeFunction("vinfolog", [](const string& arg) { VERBOSESLOG(infolog("%s", arg), - dnsdist::logging::getTopLogger()->withName("lua-message")->info(Logr::Info, arg)); + dnsdist::logging::getTopLogger("lua-message")->info(Logr::Info, arg)); }); luaCtx.writeFunction("infolog", [](const string& arg) { SLOG(infolog("%s", arg), - dnsdist::logging::getTopLogger()->withName("lua-message")->info(Logr::Info, arg)); + dnsdist::logging::getTopLogger("lua-message")->info(Logr::Info, arg)); }); luaCtx.writeFunction("errlog", [](const string& arg) { SLOG(errlog("%s", arg), - dnsdist::logging::getTopLogger()->withName("lua-message")->info(Logr::Error, arg)); + dnsdist::logging::getTopLogger("lua-message")->info(Logr::Error, arg)); }); luaCtx.writeFunction("warnlog", [](const string& arg) { SLOG(warnlog("%s", arg), - dnsdist::logging::getTopLogger()->withName("lua-message")->info(Logr::Warning, arg)); + dnsdist::logging::getTopLogger("lua-message")->info(Logr::Warning, arg)); }); luaCtx.writeFunction("show", [](const string& arg) { g_outputBuffer += arg; @@ -1097,7 +1097,7 @@ void setupLuaBindings(LuaContext& luaCtx, bool client, bool configCheck) } catch (const std::exception& exp) { VERBOSESLOG(infolog("Error during execution of getAddressInfo callback: %s", exp.what()), - dnsdist::logging::getTopLogger()->error(Logr::Error, exp.what(), "Error during execution of getAddressInfo callback")); + dnsdist::logging::getTopLogger("getAddressInfo")->error(Logr::Error, exp.what(), "Error during execution of getAddressInfo callback")); } // this _needs_ to be done while we are holding the lock, // otherwise the destructor will corrupt the stack diff --git a/pdns/dnsdistdist/dnsdist-lua-configuration-items.cc b/pdns/dnsdistdist/dnsdist-lua-configuration-items.cc index 1a4afe5989..4e56f071ab 100644 --- a/pdns/dnsdistdist/dnsdist-lua-configuration-items.cc +++ b/pdns/dnsdistdist/dnsdist-lua-configuration-items.cc @@ -101,14 +101,14 @@ static const std::map s_unsigned {"setPayloadSizeOnSelfGeneratedAnswers", {[](dnsdist::configuration::RuntimeConfiguration& config, uint64_t newValue) { if (newValue < 512) { SLOG(warnlog("setPayloadSizeOnSelfGeneratedAnswers() is set too low, using 512 instead!"), - dnsdist::logging::getTopLogger()->withName("configuration")->info(Logr::Warning, "Value passed to setPayloadSizeOnSelfGeneratedAnswers() is set too low, using 512 instead", "value", Logging::Loggable(newValue))); + dnsdist::logging::getTopLogger("configuration")->info(Logr::Warning, "Value passed to setPayloadSizeOnSelfGeneratedAnswers() is set too low, using 512 instead", "value", Logging::Loggable(newValue))); g_outputBuffer = "setPayloadSizeOnSelfGeneratedAnswers() is set too low, using 512 instead!"; newValue = 512; } if (newValue > dnsdist::configuration::s_udpIncomingBufferSize) { SLOG(warnlog("setPayloadSizeOnSelfGeneratedAnswers() is set too high, capping to %d instead!", dnsdist::configuration::s_udpIncomingBufferSize), - dnsdist::logging::getTopLogger()->withName("configuration")->info(Logr::Warning, "Value passed to setPayloadSizeOnSelfGeneratedAnswers() is set too high, capping", "value", Logging::Loggable(newValue), "cap", Logging::Loggable(dnsdist::configuration::s_udpIncomingBufferSize))); + dnsdist::logging::getTopLogger("configuration")->info(Logr::Warning, "Value passed to setPayloadSizeOnSelfGeneratedAnswers() is set too high, capping", "value", Logging::Loggable(newValue), "cap", Logging::Loggable(dnsdist::configuration::s_udpIncomingBufferSize))); g_outputBuffer = "setPayloadSizeOnSelfGeneratedAnswers() is set too high, capping to " + std::to_string(dnsdist::configuration::s_udpIncomingBufferSize) + " instead"; newValue = dnsdist::configuration::s_udpIncomingBufferSize; } @@ -215,7 +215,7 @@ void setupConfigurationItems(LuaContext& luaCtx) catch (const std::exception& exp) { g_outputBuffer = name + " cannot be used at runtime!\n"; SLOG(errlog("%s cannot be used at runtime!", name), - dnsdist::logging::getTopLogger()->withName("configuration")->info(Logr::Error, "The " + name + " directive cannot be used at runtime")); + dnsdist::logging::getTopLogger("configuration")->info(Logr::Error, "The " + name + " directive cannot be used at runtime")); } }); } @@ -231,7 +231,7 @@ void setupConfigurationItems(LuaContext& luaCtx) catch (const std::exception& exp) { g_outputBuffer = name + " cannot be used at runtime!\n"; SLOG(errlog("%s cannot be used at runtime!", name), - dnsdist::logging::getTopLogger()->withName("configuration")->info(Logr::Error, "The " + name + " directive cannot be used at runtime")); + dnsdist::logging::getTopLogger("configuration")->info(Logr::Error, "The " + name + " directive cannot be used at runtime")); } }); } @@ -240,7 +240,7 @@ void setupConfigurationItems(LuaContext& luaCtx) if (value != 0 && value < item.minimumValue) { g_outputBuffer = "Invalid value passed to " + name + "()!\n"; SLOG(errlog("Invalid value passed to %s()!", name), - dnsdist::logging::getTopLogger()->withName("configuration")->info(Logr::Error, "Invalid value passed to " + name, "value", Logging::Loggable(value))); + dnsdist::logging::getTopLogger("configuration")->info(Logr::Error, "Invalid value passed to " + name, "value", Logging::Loggable(value))); return; } @@ -252,7 +252,7 @@ void setupConfigurationItems(LuaContext& luaCtx) catch (const std::exception& exp) { g_outputBuffer = name + " cannot be used at runtime!\n"; SLOG(errlog("%s cannot be used at runtime!", name), - dnsdist::logging::getTopLogger()->withName("configuration")->info(Logr::Error, "The " + name + " directive cannot be used at runtime")); + dnsdist::logging::getTopLogger("configuration")->info(Logr::Error, "The " + name + " directive cannot be used at runtime")); } setLuaSideEffect(); }); diff --git a/pdns/dnsdistdist/dnsdist-lua-ffi.cc b/pdns/dnsdistdist/dnsdist-lua-ffi.cc index 86f8f8f1a5..ac1512d3a1 100644 --- a/pdns/dnsdistdist/dnsdist-lua-ffi.cc +++ b/pdns/dnsdistdist/dnsdist-lua-ffi.cc @@ -40,7 +40,7 @@ static std::shared_ptr getLogger(const std::string_view fromFunction) { - return dnsdist::logging::getTopLogger()->withName("lua-ffi-script")->withValues("lua.ffi.function", Logging::Loggable(fromFunction)); + return dnsdist::logging::getTopLogger("lua-ffi-script")->withValues("lua.ffi.function", Logging::Loggable(fromFunction)); } uint16_t dnsdist_ffi_dnsquestion_get_qtype(const dnsdist_ffi_dnsquestion_t* dq) diff --git a/pdns/dnsdistdist/dnsdist-lua-hooks.cc b/pdns/dnsdistdist/dnsdist-lua-hooks.cc index bef83c2af8..7080f0cd6b 100644 --- a/pdns/dnsdistdist/dnsdist-lua-hooks.cc +++ b/pdns/dnsdistdist/dnsdist-lua-hooks.cc @@ -63,7 +63,7 @@ static void setTicketsKeyAddedHook(const LuaContext& context, const TicketsKeyAd } catch (const std::exception& exp) { SLOG(warnlog("Error calling the Lua hook after new tickets key has been added: %s", exp.what()), - dnsdist::logging::getTopLogger()->error(Logr::Warning, exp.what(), "Error calling the Lua hook after a new ticket key has been added")); + dnsdist::logging::getTopLogger("ticket-keys-hook")->error(Logr::Warning, exp.what(), "Error calling the Lua hook after a new ticket key has been added")); } }); } diff --git a/pdns/dnsdistdist/dnsdist-lua-inspection.cc b/pdns/dnsdistdist/dnsdist-lua-inspection.cc index 9d36b90498..22bf3c8c70 100644 --- a/pdns/dnsdistdist/dnsdist-lua-inspection.cc +++ b/pdns/dnsdistdist/dnsdist-lua-inspection.cc @@ -1139,12 +1139,12 @@ void setupLuaInspection(LuaContext& luaCtx) } catch (const std::exception& exp) { SLOG(errlog("addDynamicBlock: Unable to parse '%s': %s", clientIPStr, exp.what()), - dnsdist::logging::getTopLogger()->error(Logr::Error, exp.what(), "Unable to parse IP address when trying to add a dynamic rule", "address", Logging::Loggable(clientIPStr), "dnsdist.lua.function", Logging::Loggable("addDynamicBlock"))); + dnsdist::logging::getTopLogger("addDynamicBlock")->error(Logr::Error, exp.what(), "Unable to parse IP address when trying to add a dynamic rule", "address", Logging::Loggable(clientIPStr), "dnsdist.lua.function", Logging::Loggable("addDynamicBlock"))); return; } catch (const PDNSException& exp) { SLOG(errlog("addDynamicBlock: Unable to parse '%s': %s", clientIPStr, exp.reason), - dnsdist::logging::getTopLogger()->error(Logr::Error, exp.reason, "Unable to parse IP address when trying to add a dynamic rule", "address", Logging::Loggable(clientIPStr), "dnsdist.lua.function", Logging::Loggable("addDynamicBlock"))); + dnsdist::logging::getTopLogger("addDynamicBlock")->error(Logr::Error, exp.reason, "Unable to parse IP address when trying to add a dynamic rule", "address", Logging::Loggable(clientIPStr), "dnsdist.lua.function", Logging::Loggable("addDynamicBlock"))); return; } } diff --git a/pdns/dnsdistdist/dnsdist-lua-network.cc b/pdns/dnsdistdist/dnsdist-lua-network.cc index da3731bee5..95af07beb8 100644 --- a/pdns/dnsdistdist/dnsdist-lua-network.cc +++ b/pdns/dnsdistdist/dnsdist-lua-network.cc @@ -82,11 +82,11 @@ void NetworkListener::readCB(int desc, FDMultiplexer::funcparam_t& param) } catch (const std::exception& e) { VERBOSESLOG(infolog("Exception in the read callback of a NetworkListener: %s", e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Info, e.what(), "Exception in the read callback of a NetworkListener")); + dnsdist::logging::getTopLogger("network-listener")->error(Logr::Info, e.what(), "Exception in the read callback of a NetworkListener")); } catch (...) { VERBOSESLOG(infolog("Exception in the read callback of a NetworkListener"), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Unknown exception in the read callback of a NetworkListener")); + dnsdist::logging::getTopLogger("network-listener")->info(Logr::Info, "Unknown exception in the read callback of a NetworkListener")); } } } @@ -109,7 +109,7 @@ bool NetworkListener::addUnixListeningEndpoint(const std::string& path, NetworkL err = errno; if (err != ENOENT) { VERBOSESLOG(infolog("Error removing Unix socket to path '%s': %s", path, stringerror(err)), - dnsdist::logging::getTopLogger()->error(Logr::Info, err, "Error removing unix socket when adding a listening endpoint to a NetworkListener", "path", Logging::Loggable(path))); + dnsdist::logging::getTopLogger("network-listener")->error(Logr::Info, err, "Error removing unix socket when adding a listening endpoint to a NetworkListener", "path", Logging::Loggable(path))); } } } diff --git a/pdns/dnsdistdist/dnsdist-lua-rules.cc b/pdns/dnsdistdist/dnsdist-lua-rules.cc index 8d841a10e8..8fbc3388ae 100644 --- a/pdns/dnsdistdist/dnsdist-lua-rules.cc +++ b/pdns/dnsdistdist/dnsdist-lua-rules.cc @@ -69,7 +69,7 @@ std::shared_ptr makeRule(const luadnsrule_t& var, const std::string& ca } if (suffixSeen) { SLOG(warnlog("At least one parameter to %s has been parsed as a domain name amongst network masks, and will be ignored!", calledFrom), - dnsdist::logging::getTopLogger()->info(Logr::Warning, "At least one parameter has been parsed as a domain name amongst network masks, and will be ignored!", "dnsdist.lua.function", Logging::Loggable(calledFrom))); + dnsdist::logging::getTopLogger("make-rule")->info(Logr::Warning, "At least one parameter has been parsed as a domain name amongst network masks, and will be ignored!", "dnsdist.lua.function", Logging::Loggable(calledFrom))); } return std::make_shared(nmg, true); } diff --git a/pdns/dnsdistdist/dnsdist-lua.cc b/pdns/dnsdistdist/dnsdist-lua.cc index 03d613628e..f4b4e5e0c9 100644 --- a/pdns/dnsdistdist/dnsdist-lua.cc +++ b/pdns/dnsdistdist/dnsdist-lua.cc @@ -122,7 +122,7 @@ void resetLuaSideEffect() static std::shared_ptr getLogger(const std::string_view context) { - static auto logger = dnsdist::logging::getTopLogger()->withName("configuration"); + static auto logger = dnsdist::logging::getTopLogger("configuration"); return logger->withValues("lua.function", Logging::Loggable(context)); } @@ -3349,11 +3349,11 @@ void loadLuaConfigurationFile(LuaContext& luaCtx, const std::string& config, boo throw std::runtime_error("Unable to read configuration file from " + config); } SLOG(warnlog("Unable to read configuration from '%s'", config), - dnsdist::logging::getTopLogger()->withName("lua-configuration")->info(Logr::Error, "Unable to read configuration from file", "path", Logging::Loggable(config))); + dnsdist::logging::getTopLogger("lua-configuration")->info(Logr::Error, "Unable to read configuration from file", "path", Logging::Loggable(config))); } else { VERBOSESLOG(infolog("Read configuration from '%s'", config), - dnsdist::logging::getTopLogger()->withName("lua-configuration")->info(Logr::Info, "Read configuration from file", "path", Logging::Loggable(config))); + dnsdist::logging::getTopLogger("lua-configuration")->info(Logr::Info, "Read configuration from file", "path", Logging::Loggable(config))); } luaCtx.executeCode(ifs); diff --git a/pdns/dnsdistdist/dnsdist-lua.hh b/pdns/dnsdistdist/dnsdist-lua.hh index f888eef0bd..8851fff5ec 100644 --- a/pdns/dnsdistdist/dnsdist-lua.hh +++ b/pdns/dnsdistdist/dnsdist-lua.hh @@ -82,7 +82,7 @@ std::optional getFunctionFromLuaCode(const std::string& code, cons } catch (const std::exception& exp) { SLOG(warnlog("Parsing Lua code '%s' in context '%s' failed: %s", code, context, exp.what()), - dnsdist::logging::getTopLogger()->withName(context)->error(Logr::Warning, exp.what(), "Parsing Lua code failed", "lua_code", Logging::Loggable(code))); + dnsdist::logging::getTopLogger(context)->error(Logr::Warning, exp.what(), "Parsing Lua code failed", "lua_code", Logging::Loggable(code))); } return std::nullopt; @@ -128,7 +128,7 @@ static inline int getOptionalValue(std::optional& vars, const std::string& ke /* key is there but isn't compatible */ if (warnOnWrongType) { SLOG(warnlog("Invalid type for key '%s' - ignored", key), - dnsdist::logging::getTopLogger()->withName("configuration")->info(Logr::Warning, "Invalid type for key passed to Lua directive, ignored", "key", Logging::Loggable(key), "value", Logging::Loggable("value"))); + dnsdist::logging::getTopLogger("configuration")->info(Logr::Warning, "Invalid type for key passed to Lua directive, ignored", "key", Logging::Loggable(key), "value", Logging::Loggable("value"))); vars->erase(key); } return -1; @@ -148,7 +148,7 @@ static inline int getOptionalIntegerValue(const std::string& func, std::optional } catch (const std::exception& e) { SLOG(warnlog("Parameter '%s' of '%s' must be integer, not '%s' - ignoring", func, key, valueStr), - dnsdist::logging::getTopLogger()->withName(func)->info(Logr::Warning, "Invalid type for integer parameter, ignored", "key", Logging::Loggable(key), "value", Logging::Loggable("value"))); + dnsdist::logging::getTopLogger(func)->info(Logr::Warning, "Invalid type for integer parameter, ignored", "key", Logging::Loggable(key), "value", Logging::Loggable("value"))); return -1; } } @@ -164,6 +164,6 @@ static inline void checkAllParametersConsumed(const std::string& func, const std } for (const auto& [key, value] : *vars) { SLOG(warnlog("%s: Unknown key '%s' given - ignored", func, key), - dnsdist::logging::getTopLogger()->withName(func)->info(Logr::Warning, "Unknown key, ignored", "key", Logging::Loggable(key), "value", Logging::Loggable("value"))); + dnsdist::logging::getTopLogger(func)->info(Logr::Warning, "Unknown key, ignored", "key", Logging::Loggable(key), "value", Logging::Loggable("value"))); } } diff --git a/pdns/dnsdistdist/dnsdist-nghttp2.cc b/pdns/dnsdistdist/dnsdist-nghttp2.cc index 855ab63ea4..be53ce1970 100644 --- a/pdns/dnsdistdist/dnsdist-nghttp2.cc +++ b/pdns/dnsdistdist/dnsdist-nghttp2.cc @@ -899,7 +899,7 @@ static void handleCrossProtocolQuery(int pipefd, FDMultiplexer::funcparam_t& par static void dohClientThread(pdns::channel::Receiver&& receiver) { setThreadName("dnsdist/dohClie"); - auto logger = dnsdist::logging::getTopLogger()->withName("outgoing-doh-worker"); + auto logger = dnsdist::logging::getTopLogger("outgoing-doh-worker"); try { DoHClientThreadData data(std::move(receiver)); @@ -1028,12 +1028,12 @@ void DoHClientCollection::addThread() auto [sender, receiver] = pdns::channel::createObjectQueue(pdns::channel::SenderBlockingMode::SenderNonBlocking, pdns::channel::ReceiverBlockingMode::ReceiverNonBlocking, internalPipeBufferSize); VERBOSESLOG(infolog("Adding DoH Client thread"), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Adding outgoing DoH worker thread")); + dnsdist::logging::getTopLogger("outgoing-doh")->info(Logr::Info, "Adding outgoing DoH worker thread")); auto lock = std::scoped_lock(d_mutex); if (d_numberOfThreads >= d_clientThreads.size()) { VERBOSESLOG(infolog("Adding a new DoH client thread would exceed the vector size (%d/%d), skipping. Consider increasing the maximum amount of DoH client threads with setMaxDoHClientThreads() in the configuration.", d_numberOfThreads, d_clientThreads.size()), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Adding a new outgoing DoH worker thread would exceed the vector size, skipping. Consider increasing the maximum amount of DoH worker threads with setMaxDoHClientThreads() in the configuration.", "workers_count", Logging::Loggable(d_numberOfThreads), "workers_limit", Logging::Loggable(d_clientThreads.size()))); + dnsdist::logging::getTopLogger("outgoing-doh")->info(Logr::Info, "Adding a new outgoing DoH worker thread would exceed the vector size, skipping. Consider increasing the maximum amount of DoH worker threads with setMaxDoHClientThreads() in the configuration.", "workers_count", Logging::Loggable(d_numberOfThreads), "workers_limit", Logging::Loggable(d_clientThreads.size()))); return; } @@ -1045,7 +1045,7 @@ void DoHClientCollection::addThread() catch (const std::runtime_error& e) { /* the thread creation failed */ SLOG(errlog("Error creating a DoH thread: %s", e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Error, e.what(), "Error creating an outgoing DoH worker thread")); + dnsdist::logging::getTopLogger("outgoing-doh")->error(Logr::Error, e.what(), "Error creating an outgoing DoH worker thread")); return; } @@ -1054,7 +1054,7 @@ void DoHClientCollection::addThread() } catch (const std::exception& e) { SLOG(errlog("Error creating the DoH channel: %s", e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Error, e.what(), "Error creating a channel for a new outgoing DoH worker")); + dnsdist::logging::getTopLogger("outgoing-doh")->error(Logr::Error, e.what(), "Error creating a channel for a new outgoing DoH worker")); return; } #else /* HAVE_DNS_OVER_HTTPS && HAVE_NGHTTP2 */ diff --git a/pdns/dnsdistdist/dnsdist-protobuf.cc b/pdns/dnsdistdist/dnsdist-protobuf.cc index a4423a5522..6559cfa454 100644 --- a/pdns/dnsdistdist/dnsdist-protobuf.cc +++ b/pdns/dnsdistdist/dnsdist-protobuf.cc @@ -204,7 +204,7 @@ void DNSDistProtoBufMessage::serialize(std::string& data, bool withOpenTelemetry } catch (const std::exception& exp) { VERBOSESLOG(infolog("Error while parsing the RRs from a response packet to add them to the protobuf message: %s", exp.what()), - dnsdist::logging::getTopLogger()->error(Logr::Info, exp.what(), "Error while parsing the RRs from a response packet to add them to the protobuf message")); + dnsdist::logging::getTopLogger("protobuf")->error(Logr::Info, exp.what(), "Error while parsing the RRs from a response packet to add them to the protobuf message")); } } else { diff --git a/pdns/dnsdistdist/dnsdist-proxy-protocol.cc b/pdns/dnsdistdist/dnsdist-proxy-protocol.cc index c2ae7c0564..4f44a5bd88 100644 --- a/pdns/dnsdistdist/dnsdist-proxy-protocol.cc +++ b/pdns/dnsdistdist/dnsdist-proxy-protocol.cc @@ -87,12 +87,12 @@ bool handleProxyProtocol(const ComboAddress& remote, bool isTCP, const NetmaskGr if (used <= 0) { ++dnsdist::metrics::g_stats.proxyProtocolInvalid; VERBOSESLOG(infolog("Ignoring invalid proxy protocol (%d, %d) query over %s from %s", query.size(), used, (isTCP ? "TCP" : "UDP"), remote.toStringWithPort()), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Ignoring invalid proxy protocol header", "dns.query.size", Logging::Loggable(query.size()), "proxy_protocol_parsed", Logging::Loggable(used), "protocol", Logging::Loggable(isTCP ? "TCP" : "UDP"), "network.peer.address", Logging::Loggable(remote))); + dnsdist::logging::getTopLogger("proxy-protocol")->info(Logr::Info, "Ignoring invalid proxy protocol header", "dns.query.size", Logging::Loggable(query.size()), "proxy_protocol_parsed", Logging::Loggable(used), "protocol", Logging::Loggable(isTCP ? "TCP" : "UDP"), "network.peer.address", Logging::Loggable(remote))); return false; } if (static_cast(used) > dnsdist::configuration::getCurrentRuntimeConfiguration().d_proxyProtocolMaximumSize) { VERBOSESLOG(infolog("Proxy protocol header in %s packet from %s is larger than proxy-protocol-maximum-size (%d), dropping", (isTCP ? "TCP" : "UDP"), remote.toStringWithPort(), used), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Proxy protocol header is larger than proxy-protocol-maximum-size, dropping", "proxy_protocol_parsed", Logging::Loggable(used), "protocol", Logging::Loggable(isTCP ? "TCP" : "UDP"), "network.peer.address", Logging::Loggable(remote))); + dnsdist::logging::getTopLogger("proxy-protocol")->info(Logr::Info, "Proxy protocol header is larger than proxy-protocol-maximum-size, dropping", "proxy_protocol_parsed", Logging::Loggable(used), "protocol", Logging::Loggable(isTCP ? "TCP" : "UDP"), "network.peer.address", Logging::Loggable(remote))); ++dnsdist::metrics::g_stats.proxyProtocolInvalid; return false; } @@ -108,7 +108,7 @@ bool handleProxyProtocol(const ComboAddress& remote, bool isTCP, const NetmaskGr if (proxyProto && dnsdist::configuration::getCurrentRuntimeConfiguration().d_applyACLToProxiedClients) { if (!acl.match(realRemote)) { VERBOSESLOG(infolog("Query from %s dropped because of ACL", realRemote.toStringWithPort()), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Query with proxy protocol header dropped because of ACL", "protocol", Logging::Loggable(isTCP ? "TCP" : "UDP"), "network.peer.address", Logging::Loggable(remote), "client.address", Logging::Loggable(realRemote))); + dnsdist::logging::getTopLogger("proxy-protocol")->info(Logr::Info, "Query with proxy protocol header dropped because of ACL", "protocol", Logging::Loggable(isTCP ? "TCP" : "UDP"), "network.peer.address", Logging::Loggable(remote), "client.address", Logging::Loggable(realRemote))); ++dnsdist::metrics::g_stats.aclDrops; return false; } diff --git a/pdns/dnsdistdist/dnsdist-secpoll.cc b/pdns/dnsdistdist/dnsdist-secpoll.cc index c618cd308a..9b13502882 100644 --- a/pdns/dnsdistdist/dnsdist-secpoll.cc +++ b/pdns/dnsdistdist/dnsdist-secpoll.cc @@ -199,7 +199,7 @@ void doSecPoll(const std::string& suffix) std::replace(queriedName.begin(), queriedName.end(), '+', '_'); std::replace(queriedName.begin(), queriedName.end(), '~', '_'); - auto logger = dnsdist::logging::getTopLogger()->withName("security-status-polling")->withValues("version", Logging::Loggable(pkgv), "dns.query.name", Logging::Loggable(queriedName)); + auto logger = dnsdist::logging::getTopLogger("security-status-polling")->withValues("version", Logging::Loggable(pkgv), "dns.query.name", Logging::Loggable(queriedName)); try { const std::string status = getSecPollStatus(*logger, queriedName); diff --git a/pdns/dnsdistdist/dnsdist-snmp.cc b/pdns/dnsdistdist/dnsdist-snmp.cc index 1a5ebd705c..77791772d2 100644 --- a/pdns/dnsdistdist/dnsdist-snmp.cc +++ b/pdns/dnsdistdist/dnsdist-snmp.cc @@ -106,13 +106,13 @@ static void registerCounter64Stat(const char* name, const OIDStat& statOID, pdns { if (statOID.size() != OID_LENGTH(queriesOID)) { SLOG(errlog("Invalid OID for SNMP Counter64 statistic %s", name), - dnsdist::logging::getTopLogger()->withName("snmp-agent")->info(Logr::Error, "Invalid OID for SNMP Counter64 metric", "metric_name", Logging::Loggable(name))); + dnsdist::logging::getTopLogger("snmp-agent")->info(Logr::Error, "Invalid OID for SNMP Counter64 metric", "metric_name", Logging::Loggable(name))); return; } if (s_statsMap.find(statOID.at(statOID.size() - 1)) != s_statsMap.end()) { SLOG(errlog("OID for SNMP Counter64 statistic %s has already been registered", name), - dnsdist::logging::getTopLogger()->withName("snmp-agent")->info(Logr::Error, "OID for SNMP Counter64 metric has already been registered", "metric_name", Logging::Loggable(name))); + dnsdist::logging::getTopLogger("snmp-agent")->info(Logr::Error, "OID for SNMP Counter64 metric has already been registered", "metric_name", Logging::Loggable(name))); return; } @@ -160,13 +160,13 @@ static void registerFloatStat(const char* name, const OIDStat& statOID, pdns::st { if (statOID.size() != OID_LENGTH(queriesOID)) { SLOG(errlog("Invalid OID for SNMP Float statistic %s", name), - dnsdist::logging::getTopLogger()->withName("snmp-agent")->info(Logr::Error, "Invalid OID for SNMP Float metric", "metric_name", Logging::Loggable(name))); + dnsdist::logging::getTopLogger("snmp-agent")->info(Logr::Error, "Invalid OID for SNMP Float metric", "metric_name", Logging::Loggable(name))); return; } if (s_statsMap.find(statOID.at(statOID.size() - 1)) != s_statsMap.end()) { SLOG(errlog("OID for SNMP Float statistic %s has already been registered", name), - dnsdist::logging::getTopLogger()->withName("snmp-agent")->info(Logr::Error, "OID for SNMP Float metric has already been registered", "metric_name", Logging::Loggable(name))); + dnsdist::logging::getTopLogger("snmp-agent")->info(Logr::Error, "OID for SNMP Float metric has already been registered", "metric_name", Logging::Loggable(name))); return; } @@ -207,13 +207,13 @@ static void registerGauge64Stat(const char* name, const OIDStat& statOID, const { if (statOID.size() != OID_LENGTH(queriesOID)) { SLOG(errlog("Invalid OID for SNMP Gauge64 statistic %s", name), - dnsdist::logging::getTopLogger()->withName("snmp-agent")->info(Logr::Error, "Invalid OID for SNMP Gauge64 metric", "metric_name", Logging::Loggable(name))); + dnsdist::logging::getTopLogger("snmp-agent")->info(Logr::Error, "Invalid OID for SNMP Gauge64 metric", "metric_name", Logging::Loggable(name))); return; } if (s_statsMap.find(statOID.at(statOID.size() - 1)) != s_statsMap.end()) { SLOG(errlog("OID for SNMP Gauge64 statistic %s has already been registered", name), - dnsdist::logging::getTopLogger()->withName("snmp-agent")->info(Logr::Error, "OID for SNMP Gauge64 metric has already been registered", "metric_name", Logging::Loggable(name))); + dnsdist::logging::getTopLogger("snmp-agent")->info(Logr::Error, "OID for SNMP Gauge64 metric has already been registered", "metric_name", Logging::Loggable(name))); return; } diff --git a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc index 18fd9bb59d..8548b072b3 100644 --- a/pdns/dnsdistdist/dnsdist-tcp-downstream.cc +++ b/pdns/dnsdistdist/dnsdist-tcp-downstream.cc @@ -917,7 +917,7 @@ bool TCPConnectionToBackend::isXFRFinished(const TCPResponse& response, TCPQuery std::shared_ptr ConnectionToBackend::getLogger() const { - auto logger = dnsdist::logging::getTopLogger()->withName("outgoing-tcp-connection")->withValues("fresh_connection", Logging::Loggable(d_fresh), "tcp_fast_open", Logging::Loggable(d_enableFastOpen), "proxy_protocol_payload_sent", Logging::Loggable(d_proxyProtocolPayloadSent), "downstream_failures", Logging::Loggable(d_downstreamFailures), "highest_stream_id", Logging::Loggable(d_highestStreamID), "queries_count", Logging::Loggable(d_queries), "io_state", Logging::Loggable(d_ioState ? d_ioState->getState() : "empty")); + auto logger = dnsdist::logging::getTopLogger("outgoing-tcp-connection")->withValues("fresh_connection", Logging::Loggable(d_fresh), "tcp_fast_open", Logging::Loggable(d_enableFastOpen), "proxy_protocol_payload_sent", Logging::Loggable(d_proxyProtocolPayloadSent), "downstream_failures", Logging::Loggable(d_downstreamFailures), "highest_stream_id", Logging::Loggable(d_highestStreamID), "queries_count", Logging::Loggable(d_queries), "io_state", Logging::Loggable(d_ioState ? d_ioState->getState() : "empty")); if (d_ds) { logger = logger->withValues("backend.address", Logging::Loggable(d_ds->d_config.remote), "backend.name", Logging::Loggable(d_ds->getName())); } diff --git a/pdns/dnsdistdist/dnsdist-tcp.cc b/pdns/dnsdistdist/dnsdist-tcp.cc index 0c0148fb13..01c410473e 100644 --- a/pdns/dnsdistdist/dnsdist-tcp.cc +++ b/pdns/dnsdistdist/dnsdist-tcp.cc @@ -194,11 +194,11 @@ void TCPClientCollection::addTCPClientThread(std::vector& tcpAccep auto [crossProtocolResponseChannelSender, crossProtocolResponseChannelReceiver] = pdns::channel::createObjectQueue(pdns::channel::SenderBlockingMode::SenderNonBlocking, pdns::channel::ReceiverBlockingMode::ReceiverNonBlocking, internalPipeBufferSize); VERBOSESLOG(infolog("Adding TCP Client thread"), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Adding TCP worker thread to handle TCP connections from clients")); + dnsdist::logging::getTopLogger("incoming-tcp-worker")->info(Logr::Info, "Adding TCP worker thread to handle TCP connections from clients")); if (d_numthreads >= d_tcpclientthreads.size()) { VERBOSESLOG(infolog("Adding a new TCP client thread would exceed the vector size (%d/%d), skipping. Consider increasing the maximum amount of TCP client threads with setMaxTCPClientThreads() in the configuration.", d_numthreads.load(), d_tcpclientthreads.size()), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Adding a new TCP client thread would exceed the vector size, skipping. Consider increasing the maximum amount of TCP client threads with setMaxTCPClientThreads() in the configuration.", "workers_count", Logging::Loggable(d_numthreads.load()), "workers_limit", Logging::Loggable(d_tcpclientthreads.size()))); + dnsdist::logging::getTopLogger("incoming-tcp-worker")->info(Logr::Info, "Adding a new TCP client thread would exceed the vector size, skipping. Consider increasing the maximum amount of TCP client threads with setMaxTCPClientThreads() in the configuration.", "workers_count", Logging::Loggable(d_numthreads.load()), "workers_limit", Logging::Loggable(d_tcpclientthreads.size()))); return; } @@ -210,7 +210,7 @@ void TCPClientCollection::addTCPClientThread(std::vector& tcpAccep } catch (const std::runtime_error& e) { SLOG(errlog("Error creating a TCP thread: %s", e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Error, e.what(), "Error creating a TCP worker thread")); + dnsdist::logging::getTopLogger("incoming-tcp-worker")->error(Logr::Error, e.what(), "Error creating a TCP worker thread")); return; } @@ -219,7 +219,7 @@ void TCPClientCollection::addTCPClientThread(std::vector& tcpAccep } catch (const std::exception& e) { SLOG(errlog("Error creating TCP worker: %s", e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Error, e.what(), "Error creating a TCP worker")); + dnsdist::logging::getTopLogger("incoming-tcp-worker")->error(Logr::Error, e.what(), "Error creating a TCP worker")); } } @@ -1474,7 +1474,7 @@ void IncomingTCPConnectionState::handleTimeout(std::shared_ptr IncomingTCPConnectionState::getLogger() const { - return dnsdist::logging::getTopLogger()->withName("incoming-tcp-connection")->withValues("client.address", Logging::Loggable(d_proxiedRemote), "frontend.address", Logging::Loggable(d_ci.cs->local), "protocol", Logging::Loggable(d_ci.cs->getProtocol()), "network.peer.address", Logging::Loggable(d_ci.remote), "destination.address", Logging::Loggable(d_proxiedDestination)); + return dnsdist::logging::getTopLogger("incoming-tcp-connection")->withValues("client.address", Logging::Loggable(d_proxiedRemote), "frontend.address", Logging::Loggable(d_ci.cs->local), "protocol", Logging::Loggable(d_ci.cs->getProtocol()), "network.peer.address", Logging::Loggable(d_ci.remote), "destination.address", Logging::Loggable(d_proxiedDestination)); } static void handleIncomingTCPQuery(int pipefd, FDMultiplexer::funcparam_t& param) @@ -1705,7 +1705,7 @@ static void tcpClientThread(pdns::channel::Receiver&& queryRecei from that point on */ setThreadName("dnsdist/tcpClie"); - auto logger = dnsdist::logging::getTopLogger()->withName("incoming-tcp-worker"); + auto logger = dnsdist::logging::getTopLogger("incoming-tcp-worker"); try { TCPClientThreadData data; @@ -1808,13 +1808,13 @@ static void acceptNewConnection(const TCPAcceptorParam& param, TCPClientThreadDa if (checkACL && !dnsdist::configuration::getCurrentRuntimeConfiguration().d_ACL.match(remote)) { ++dnsdist::metrics::g_stats.aclDrops; VERBOSESLOG(infolog("Dropped TCP connection from %s because of ACL", remote.toStringWithPort()), - dnsdist::logging::getTopLogger()->withName("incoming-tcp-worker")->info(Logr::Info, "Dropped TCP connection because of ACL", "frontend.address", Logging::Loggable(param.local), "client.address", Logging::Loggable(remote))); + dnsdist::logging::getTopLogger("incoming-tcp-worker")->info(Logr::Info, "Dropped TCP connection because of ACL", "frontend.address", Logging::Loggable(param.local), "client.address", Logging::Loggable(remote))); return; } if (clientState.d_tcpConcurrentConnectionsLimit > 0 && concurrentConnections > clientState.d_tcpConcurrentConnectionsLimit) { VERBOSESLOG(infolog("Dropped TCP connection from %s because of concurrent connections limit", remote.toStringWithPort()), - dnsdist::logging::getTopLogger()->withName("incoming-tcp-worker")->info(Logr::Info, "Dropped TCP connection because of concurrent connections limit", "frontend.address", Logging::Loggable(param.local), "client.address", Logging::Loggable(remote))); + dnsdist::logging::getTopLogger("incoming-tcp-worker")->info(Logr::Info, "Dropped TCP connection because of concurrent connections limit", "frontend.address", Logging::Loggable(param.local), "client.address", Logging::Loggable(remote))); return; } @@ -1833,7 +1833,7 @@ static void acceptNewConnection(const TCPAcceptorParam& param, TCPClientThreadDa const auto maxTCPQueuedConnections = dnsdist::configuration::getImmutableConfiguration().d_maxTCPQueuedConnections; if (maxTCPQueuedConnections > 0 && g_tcpclientthreads->getQueuedCount() >= maxTCPQueuedConnections) { VERBOSESLOG(infolog("Dropping TCP connection from %s because we have too many queued already", remote.toStringWithPort()), - dnsdist::logging::getTopLogger()->withName("incoming-tcp-worker")->info(Logr::Info, "Dropped TCP connection because we have too many queued already", "frontend.address", Logging::Loggable(param.local), "client.address", Logging::Loggable(remote))); + dnsdist::logging::getTopLogger("incoming-tcp-worker")->info(Logr::Info, "Dropped TCP connection because we have too many queued already", "frontend.address", Logging::Loggable(param.local), "client.address", Logging::Loggable(remote))); return; } @@ -1847,7 +1847,7 @@ static void acceptNewConnection(const TCPAcceptorParam& param, TCPClientThreadDa } VERBOSESLOG(infolog("Got TCP connection from %s", remote.toStringWithPort()), - dnsdist::logging::getTopLogger()->withName("incoming-tcp-worker")->info(Logr::Info, "Accepted new TCP connection", "frontend.address", Logging::Loggable(param.local), "client.address", Logging::Loggable(remote))); + dnsdist::logging::getTopLogger("incoming-tcp-worker")->info(Logr::Info, "Accepted new TCP connection", "frontend.address", Logging::Loggable(param.local), "client.address", Logging::Loggable(remote))); connInfo.remote = remote; @@ -1876,7 +1876,7 @@ static void acceptNewConnection(const TCPAcceptorParam& param, TCPClientThreadDa } catch (const std::exception& e) { SLOG(errlog("While reading a TCP question: %s", e.what()), - dnsdist::logging::getTopLogger()->withName("incoming-tcp-worker")->error(Logr::Error, e.what(), "Error while accepting a TCP connection", "frontend.address", Logging::Loggable(param.local))); + dnsdist::logging::getTopLogger("incoming-tcp-worker")->error(Logr::Error, e.what(), "Error while accepting a TCP connection", "frontend.address", Logging::Loggable(param.local))); if (tcpClientCountIncremented) { dnsdist::IncomingConcurrentTCPConnectionsManager::accountClosedTCPConnection(remote); } diff --git a/pdns/dnsdistdist/dnsdist-web.cc b/pdns/dnsdistdist/dnsdist-web.cc index c242be5ab6..5f546ce9ec 100644 --- a/pdns/dnsdistdist/dnsdist-web.cc +++ b/pdns/dnsdistdist/dnsdist-web.cc @@ -1995,7 +1995,7 @@ void setMaxConcurrentConnections(size_t max) void WebserverThread(ComboAddress listeningAddress, Socket sock) { setThreadName("dnsdist/webserv"); - auto serverLogger = dnsdist::logging::getTopLogger()->withName("webserver")->withValues("network.local.address", Logging::Loggable(listeningAddress)); + auto serverLogger = dnsdist::logging::getTopLogger("webserver")->withValues("network.local.address", Logging::Loggable(listeningAddress)); SLOG(infolog("Webserver launched on %s", listeningAddress.toStringWithPort()), serverLogger->info(Logr::Info, "Webserver launched")); diff --git a/pdns/dnsdistdist/dnsdist-xsk.cc b/pdns/dnsdistdist/dnsdist-xsk.cc index 9531226f74..d66b5dea22 100644 --- a/pdns/dnsdistdist/dnsdist-xsk.cc +++ b/pdns/dnsdistdist/dnsdist-xsk.cc @@ -39,7 +39,7 @@ void XskResponderThread(std::shared_ptr dss, std::shared_ptrwithName("xsk-response-worker")->withValues("backend.name", Logging::Loggable(dss->getName()), "backend.address", Logging::Loggable(dss->d_config.remote)); + auto logger = dnsdist::logging::getTopLogger("xsk-response-worker")->withValues("backend.name", Logging::Loggable(dss->getName()), "backend.address", Logging::Loggable(dss->d_config.remote)); auto pollfds = getPollFdsForWorker(*xskInfo); while (!dss->isStopped()) { @@ -105,15 +105,15 @@ void XskResponderThread(std::shared_ptr dss, std::shared_ptrerror(Logr::Error, e.what(), "XSK responder thread died because of exception")); + dnsdist::logging::getTopLogger("xsk-response-worker")->error(Logr::Error, e.what(), "XSK responder thread died because of exception")); } catch (const PDNSException& e) { SLOG(errlog("XSK responder thread died because of PowerDNS exception: %s", e.reason), - dnsdist::logging::getTopLogger()->error(Logr::Error, e.reason, "XSK responder thread died because of exception")); + dnsdist::logging::getTopLogger("xsk-response-worker")->error(Logr::Error, e.reason, "XSK responder thread died because of exception")); } catch (...) { SLOG(errlog("XSK responder thread died because of an unknown exception"), - dnsdist::logging::getTopLogger()->info(Logr::Error, "XSK responder thread died because of an unknown exception")); + dnsdist::logging::getTopLogger("xsk-response-worker")->info(Logr::Error, "XSK responder thread died because of an unknown exception")); } } @@ -123,7 +123,7 @@ bool XskIsQueryAcceptable(const XskPacket& packet, ClientState& clientState, boo expectProxyProtocol = expectProxyProtocolFrom(from); if (!dnsdist::configuration::getCurrentRuntimeConfiguration().d_ACL.match(from) && !expectProxyProtocol) { VERBOSESLOG(infolog("Query from %s dropped because of ACL", from.toStringWithPort()), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Query dropped because of ACL", "client.address", Logging::Loggable(from))); + dnsdist::logging::getTopLogger("xsk-frontend-worker")->info(Logr::Info, "Query dropped because of ACL", "client.address", Logging::Loggable(from))); ++dnsdist::metrics::g_stats.aclDrops; return false; } @@ -136,7 +136,7 @@ bool XskIsQueryAcceptable(const XskPacket& packet, ClientState& clientState, boo void XskRouter(std::shared_ptr xsk) { setThreadName("dnsdist/XskRouter"); - auto logger = dnsdist::logging::getTopLogger()->withName("xsk-router"); + auto logger = dnsdist::logging::getTopLogger("xsk-router"); uint32_t failed = 0; // packets to be submitted for sending diff --git a/pdns/dnsdistdist/dnsdist.cc b/pdns/dnsdistdist/dnsdist.cc index dbf2b6b572..5a7f41636c 100644 --- a/pdns/dnsdistdist/dnsdist.cc +++ b/pdns/dnsdistdist/dnsdist.cc @@ -140,7 +140,7 @@ static void sendfromto(int sock, const PacketBuffer& buffer, const ComboAddress& if (ret == -1) { int error = errno; VERBOSESLOG(infolog("Error sending UDP response to %s: %s", dest.toStringWithPort(), stringerror(error)), - dnsdist::logging::getTopLogger()->withName("sendfromto")->error(error, "Error sending UDP response", "client.address", Logging::Loggable(dest))); + dnsdist::logging::getTopLogger("sendfromto")->error(error, "Error sending UDP response", "client.address", Logging::Loggable(dest))); } return; } @@ -150,7 +150,7 @@ static void sendfromto(int sock, const PacketBuffer& buffer, const ComboAddress& } catch (const std::exception& exp) { VERBOSESLOG(infolog("Error sending UDP response from %s to %s: %s", from.toStringWithPort(), dest.toStringWithPort(), exp.what()), - dnsdist::logging::getTopLogger()->withName("sendfromto")->error(exp.what(), "Error sending UDP response", "source.address", Logging::Loggable(from), "client.address", Logging::Loggable(dest))); + dnsdist::logging::getTopLogger("sendfromto")->error(exp.what(), "Error sending UDP response", "source.address", Logging::Loggable(from), "client.address", Logging::Loggable(dest))); } } @@ -294,7 +294,7 @@ bool responseContentMatches(const PacketBuffer& response, const DNSName& qname, catch (const std::exception& e) { if (remote && !response.empty() && static_cast(response.size()) > sizeof(dnsheader)) { VERBOSESLOG(infolog("Backend %s sent us a response with id %d that did not parse: %s", remote->d_config.remote.toStringWithPort(), ntohs(dnsHeader->id), e.what()), - dnsdist::logging::getTopLogger()->withName("udp-response-worker")->error(e.what(), "Received a DNS response from a backend that we could not parse", "backend.address", Logging::Loggable(remote->d_config.remote), "dns.query.id", Logging::Loggable(ntohs(dnsHeader->id)))); + dnsdist::logging::getTopLogger("udp-response-worker")->error(e.what(), "Received a DNS response from a backend that we could not parse", "backend.address", Logging::Loggable(remote->d_config.remote), "dns.query.id", Logging::Loggable(ntohs(dnsHeader->id)))); } ++dnsdist::metrics::g_stats.nonCompliantResponses; if (remote) { @@ -393,7 +393,7 @@ static bool fixUpResponse(PacketBuffer& response, const DNSName& qname, uint16_t } else { SLOG(warnlog("Error rewriting content"), - dnsdist::logging::getTopLogger()->withName("fixup-response")->info(Logr::Error, "Error rewriting response content", "dns.question.name", Logging::Loggable(qname))); + dnsdist::logging::getTopLogger("fixup-response")->info(Logr::Error, "Error rewriting response content", "dns.question.name", Logging::Loggable(qname))); } } } @@ -416,7 +416,7 @@ static bool fixUpResponse(PacketBuffer& response, const DNSName& qname, uint16_t } else { SLOG(warnlog("Error rewriting content"), - dnsdist::logging::getTopLogger()->withName("fixup-response")->info(Logr::Error, "Error rewriting response content", "dns.question.name", Logging::Loggable(qname))); + dnsdist::logging::getTopLogger("fixup-response")->info(Logr::Error, "Error rewriting response content", "dns.question.name", Logging::Loggable(qname))); } } } @@ -434,7 +434,7 @@ static bool encryptResponse(PacketBuffer& response, size_t maximumSize, bool tcp if (res != 0) { /* dropping response */ VERBOSESLOG(infolog("Error encrypting the response, dropping."), - dnsdist::logging::getTopLogger()->withName("dnscrypt")->info(Logr::Error, "Error encrypting response, dropping")); + dnsdist::logging::getTopLogger("dnscrypt")->info(Logr::Error, "Error encrypting response, dropping")); return false; } } @@ -779,7 +779,7 @@ bool processResponderPacket(std::shared_ptr& dss, PacketBuffer& // listens on a dedicated socket, lobs answers from downstream servers to original requestors void responderThread(std::shared_ptr dss) { - auto responderLogger = dnsdist::logging::getTopLogger()->withName("udp-response")->withValues("backend.address", Logging::Loggable(dss->d_config.remote)); + auto responderLogger = dnsdist::logging::getTopLogger("udp-response")->withValues("backend.address", Logging::Loggable(dss->d_config.remote)); try { setThreadName("dnsdist/respond"); @@ -1278,7 +1278,7 @@ ssize_t udpClientSendRequestToBackend(const std::shared_ptr& ba if (result == -1) { int savederrno = errno; VERBOSESLOG(infolog("Error sending request to backend %s: %s", backend->d_config.remote.toStringWithPort(), stringerror(savederrno)), - dnsdist::logging::getTopLogger()->error(savederrno, "Error sending request to the backend", "backend.address", Logging::Loggable(backend->d_config.remote))); + dnsdist::logging::getTopLogger("udp-frontend")->error(savederrno, "Error sending request to the backend", "backend.address", Logging::Loggable(backend->d_config.remote))); /* This might sound silly, but on Linux send() might fail with EINVAL if the interface the socket was bound to doesn't exist anymore. @@ -1301,7 +1301,7 @@ static bool isUDPQueryAcceptable(ClientState& clientState, const struct msghdr* if ((msgh->msg_flags & MSG_TRUNC) != 0) { /* message was too large for our buffer */ VERBOSESLOG(infolog("Dropping message too large for our buffer"), - dnsdist::logging::getTopLogger()->info("Dropping query from client that is too large for our buffer", "client.address", Logging::Loggable(remote), "destination.address", Logging::Loggable(dest), "frontend.address", Logging::Loggable(clientState.local))); + dnsdist::logging::getTopLogger("udp-query")->info("Dropping query from client that is too large for our buffer", "client.address", Logging::Loggable(remote), "destination.address", Logging::Loggable(dest), "frontend.address", Logging::Loggable(clientState.local))); ++clientState.nonCompliantQueries; ++dnsdist::metrics::g_stats.nonCompliantQueries; return false; @@ -1310,7 +1310,7 @@ static bool isUDPQueryAcceptable(ClientState& clientState, const struct msghdr* expectProxyProtocol = clientState.d_enableProxyProtocol && expectProxyProtocolFrom(remote); if (!dnsdist::configuration::getCurrentRuntimeConfiguration().d_ACL.match(remote) && !expectProxyProtocol) { VERBOSESLOG(infolog("Query from %s dropped because of ACL", remote.toStringWithPort()), - dnsdist::logging::getTopLogger()->info("Query dropped because of ACL", "source.address", Logging::Loggable(dest))); + dnsdist::logging::getTopLogger("udp-query")->info("Query dropped because of ACL", "source.address", Logging::Loggable(dest))); ++dnsdist::metrics::g_stats.aclDrops; return false; } @@ -1727,7 +1727,7 @@ void handleServerStateChange(const string& nameWithAddr, bool newResult) } catch (const std::exception& exp) { SLOG(warnlog("Error calling the Lua hook for Server State Change: %s", exp.what()), - dnsdist::logging::getTopLogger()->error(exp.what(), "Error calling the Lua hook for backend state change", "backend.name", Logging::Loggable(nameWithAddr))); + dnsdist::logging::getTopLogger("backend-state-update")->error(exp.what(), "Error calling the Lua hook for backend state change", "backend.name", Logging::Loggable(nameWithAddr))); } } @@ -2066,7 +2066,7 @@ static void processUDPQuery(ClientState& clientState, const struct msghdr* msgh, } catch (const std::exception& e) { VERBOSESLOG(infolog("Got an error in UDP question thread while parsing a query from %s, id %d: %s", ids.origRemote.toStringWithPort(), queryId, e.what()), - dnsdist::logging::getTopLogger()->error(e.what(), "Got an error in UDP question thread while parsing a query", "source.address", Logging::Loggable(ids.origRemote), "dns.question.id", Logging::Loggable(queryId))); + dnsdist::logging::getTopLogger("udp-frontend")->error(e.what(), "Got an error in UDP question thread while parsing a query", "source.address", Logging::Loggable(ids.origRemote), "dns.question.id", Logging::Loggable(queryId))); } } @@ -2192,7 +2192,7 @@ bool XskProcessQuery(ClientState& clientState, XskPacket& packet) } catch (const std::exception& e) { VERBOSESLOG(infolog("Got an error in UDP question thread while parsing a query from %s, id %d: %s", ids.origRemote.toStringWithPort(), queryId, e.what()), - dnsdist::logging::getTopLogger()->error(e.what(), "Got an error in XSK UDP question thread while parsing a query", "source.address", Logging::Loggable(ids.origRemote), "dns.question.id", Logging::Loggable(queryId))); + dnsdist::logging::getTopLogger("udp-xsk-frontend")->error(e.what(), "Got an error in XSK UDP question thread while parsing a query", "source.address", Logging::Loggable(ids.origRemote), "dns.question.id", Logging::Loggable(queryId))); } return false; } @@ -2265,7 +2265,7 @@ static void MultipleMessagesUDPClientThread(ClientState* clientState) if (msgsGot <= 0) { int savederrno = errno; VERBOSESLOG(infolog("Getting UDP messages via recvmmsg() failed with: %s", stringerror(savederrno)), - dnsdist::logging::getTopLogger()->error(savederrno, "Getting UDP messages via recvmmsg failed", "frontend.address", Logging::Loggable(clientState->local))); + dnsdist::logging::getTopLogger("udp-recvmmsg-frontend")->error(savederrno, "Getting UDP messages via recvmmsg failed", "frontend.address", Logging::Loggable(clientState->local))); msgsGot = 0; continue; } @@ -2300,7 +2300,7 @@ static void MultipleMessagesUDPClientThread(ClientState* clientState) if (sent < 0 || static_cast(sent) != msgsToSend) { int savederrno = errno; VERBOSESLOG(infolog("Error sending responses with sendmmsg() (%d on %u): %s", sent, msgsToSend, stringerror(savederrno)), - dnsdist::logging::getTopLogger()->error(savederrno, "Error sending responses with sendmmsg()", "address", Logging::Loggable(clientState->local), "dnsdist.sendmmsg.messages_sent", Logging::Loggable(sent), "dnsdist.sendmmsg.messages_to_send", Logging::Loggable(msgsToSend))); + dnsdist::logging::getTopLogger("udp-sendmmsg-frontend")->error(savederrno, "Error sending responses with sendmmsg()", "address", Logging::Loggable(clientState->local), "dnsdist.sendmmsg.messages_sent", Logging::Loggable(sent), "dnsdist.sendmmsg.messages_to_send", Logging::Loggable(msgsToSend))); } } } @@ -2419,15 +2419,15 @@ static void udpClientThread(std::vector states) } catch (const std::exception& e) { SLOG(errlog("UDP client thread died because of exception: %s", e.what()), - dnsdist::logging::getTopLogger()->error(e.what(), "UDP client thread died because of exception")); + dnsdist::logging::getTopLogger("udp-frontend")->error(e.what(), "UDP client thread died because of exception")); } catch (const PDNSException& e) { SLOG(errlog("UDP client thread died because of PowerDNS exception: %s", e.reason), - dnsdist::logging::getTopLogger()->error(e.reason, "UDP client thread died because of PowerDNS exception")); + dnsdist::logging::getTopLogger("udp-frontend")->error(e.reason, "UDP client thread died because of PowerDNS exception")); } catch (...) { SLOG(errlog("UDP client thread died because of an exception: unknown"), - dnsdist::logging::getTopLogger()->info(Logr::Error, "UDP client thread died because of an unknown exception")); + dnsdist::logging::getTopLogger("udp-frontend")->info(Logr::Error, "UDP client thread died because of an unknown exception")); } } @@ -2458,7 +2458,7 @@ static void maintThread() catch (const std::exception& e) { if (secondsToWaitLog <= 0) { SLOG(warnlog("Error during execution of maintenance function(s): %s", e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Warning, e.what(), "Error during execution of maintenance function(s)")); + dnsdist::logging::getTopLogger("maintenance")->error(Logr::Warning, e.what(), "Error during execution of maintenance function(s)")); secondsToWaitLog = 61; } secondsToWaitLog -= interval; @@ -2603,12 +2603,12 @@ static void healthChecksThread() } catch (const std::exception& exp) { VERBOSESLOG(infolog("Exception in the health-check thread: %s", exp.what()), - dnsdist::logging::getTopLogger()->error(exp.what(), "Exception in the health-check thread")); + dnsdist::logging::getTopLogger("health-check")->error(exp.what(), "Exception in the health-check thread")); } } } -static void bindAny([[maybe_unused]] int addressFamily, [[maybe_unused]] int sock, [[maybe_unused]] const std::shared_ptr& logger) +static void bindAny([[maybe_unused]] int addressFamily, [[maybe_unused]] int sock, [[maybe_unused]] const std::shared_ptr& logger) { __attribute__((unused)) int one = 1; @@ -2649,12 +2649,12 @@ static void dropGroupPrivs(gid_t gid) if (setgid(gid) == 0) { if (setgroups(0, nullptr) < 0) { SLOG(warnlog("Warning: Unable to drop supplementary gids: %s", stringerror()), - dnsdist::logging::getTopLogger()->error(Logr::Warning, stringerror(), "Warning: Unable to drop supplementary gids")); + dnsdist::logging::getTopLogger("setup")->error(Logr::Warning, stringerror(), "Warning: Unable to drop supplementary gids")); } } else { SLOG(warnlog("Warning: Unable to set group ID to %d: %s", gid, stringerror()), - dnsdist::logging::getTopLogger()->error(Logr::Warning, stringerror(), "Warning: Unable to set group ID", "systemd.gid", Logging::Loggable(gid))); + dnsdist::logging::getTopLogger("setup")->error(Logr::Warning, stringerror(), "Warning: Unable to set group ID", "systemd.gid", Logging::Loggable(gid))); } } } @@ -2664,7 +2664,7 @@ static void dropUserPrivs(uid_t uid) if (uid != 0) { if (setuid(uid) < 0) { SLOG(warnlog("Warning: Unable to set user ID to %d: %s", uid, stringerror()), - dnsdist::logging::getTopLogger()->error(Logr::Warning, stringerror(), "Warning: Unable to set user ID", "system.uid", Logging::Loggable(uid))); + dnsdist::logging::getTopLogger("setup")->error(Logr::Warning, stringerror(), "Warning: Unable to set user ID", "system.uid", Logging::Loggable(uid))); } } } @@ -2712,18 +2712,18 @@ static void checkFileDescriptorsLimits(size_t udpBindsCount, size_t tcpBindsCoun getrlimit(RLIMIT_NOFILE, &resourceLimits); if (resourceLimits.rlim_cur <= requiredFDsCount) { SLOG(warnlog("Warning, this configuration can use more than %d file descriptors, web server and console connections not included, and the current limit is %d.", std::to_string(requiredFDsCount), std::to_string(resourceLimits.rlim_cur)), - dnsdist::logging::getTopLogger()->info(Logr::Warning, "Warning, this configuration can use more file descriptors, web server and console connections not included, than the currently configured limit", "system.required_file_descriptors", Logging::Loggable(requiredFDsCount), "system.file_descriptors_limit", Logging::Loggable(resourceLimits.rlim_cur))); + dnsdist::logging::getTopLogger("setup")->info(Logr::Warning, "Warning, this configuration can use more file descriptors, web server and console connections not included, than the currently configured limit", "system.required_file_descriptors", Logging::Loggable(requiredFDsCount), "system.file_descriptors_limit", Logging::Loggable(resourceLimits.rlim_cur))); #ifdef HAVE_SYSTEMD SLOG(warnlog("You can increase this value by using LimitNOFILE= in the systemd unit file or ulimit."), - dnsdist::logging::getTopLogger()->info(Logr::Warning, "You can increase this value by using LimitNOFILE= in the systemd unit file over ulimit")); + dnsdist::logging::getTopLogger("setup")->info(Logr::Warning, "You can increase this value by using LimitNOFILE= in the systemd unit file over ulimit")); #else SLOG(warnlog("You can increase this value by using ulimit."), - dnsdist::logging::getTopLogger()->info(Logr::Warning, "You can increase this value by using ulimit.")); + dnsdist::logging::getTopLogger("setup")->info(Logr::Warning, "You can increase this value by using ulimit.")); #endif } } -static void setupLocalSocket(ClientState& clientState, const ComboAddress& addr, int& socket, bool tcp, bool warn, const std::shared_ptr& logger) +static void setupLocalSocket(ClientState& clientState, const ComboAddress& addr, int& socket, bool tcp, bool warn, const std::shared_ptr& logger) { const auto& immutableConfig = dnsdist::configuration::getImmutableConfiguration(); static bool s_warned_ipv6_recvpktinfo = false; @@ -2922,7 +2922,7 @@ static void setupLocalSocket(ClientState& clientState, const ComboAddress& addr, } } -static void setUpLocalBind(ClientState& cstate, const std::shared_ptr& logger) +static void setUpLocalBind(ClientState& cstate, const std::shared_ptr& logger) { /* skip some warnings if there is an identical UDP context */ bool warn = !cstate.tcp || cstate.tlsFrontend != nullptr || cstate.dohFrontend != nullptr; @@ -3312,7 +3312,7 @@ static void parseParameters(int argc, char** argv, CommandLineParameters& cmdLin config = std::move(newConfig); }); } -static void setupPools(const std::shared_ptr& logger) +static void setupPools(const std::shared_ptr& logger) { bool precompute = false; const auto& currentConfig = dnsdist::configuration::getCurrentRuntimeConfiguration(); @@ -3364,7 +3364,7 @@ static void dropPrivileges(const CommandLineParameters& cmdLine) if (getegid() != newgid) { if (running_in_service_mgr()) { SLOG(errlog("--gid/-g set on command-line, but dnsdist was started as a systemd service. Use the 'Group' setting in the systemd unit file to set the group to run as"), - dnsdist::logging::getTopLogger()->info(Logr::Error, "--gid/-g set on command-line, but dnsdist was started as a systemd service. Use the 'Group' setting in the systemd unit file to set the group to run as")); + dnsdist::logging::getTopLogger("setup")->info(Logr::Error, "--gid/-g set on command-line, but dnsdist was started as a systemd service. Use the 'Group' setting in the systemd unit file to set the group to run as")); _exit(EXIT_FAILURE); } dropGroupPrivs(newgid); @@ -3373,7 +3373,7 @@ static void dropPrivileges(const CommandLineParameters& cmdLine) if (geteuid() != newuid) { if (running_in_service_mgr()) { SLOG(errlog("--uid/-u set on command-line, but dnsdist was started as a systemd service. Use the 'User' setting in the systemd unit file to set the user to run as"), - dnsdist::logging::getTopLogger()->info(Logr::Error, "--uid/-u set on command-line, but dnsdist was started as a systemd service. Use the 'User' setting in the systemd unit file to set the user to run as")); + dnsdist::logging::getTopLogger("setup")->info(Logr::Error, "--uid/-u set on command-line, but dnsdist was started as a systemd service. Use the 'User' setting in the systemd unit file to set the user to run as")); _exit(EXIT_FAILURE); } dropUserPrivs(newuid); @@ -3394,7 +3394,7 @@ static void dropPrivileges(const CommandLineParameters& cmdLine) } catch (const std::exception& e) { SLOG(warnlog("%s", e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Warning, e.what(), "Error while dropping capabilities")); + dnsdist::logging::getTopLogger("setup")->error(Logr::Warning, e.what(), "Error while dropping capabilities")); } } @@ -3534,7 +3534,7 @@ static ListeningSockets initListeningSockets() } catch (const std::exception& exp) { SLOG(errlog("Unable to bind to control socket on %s: %s", local.toStringWithPort(), exp.what()), - dnsdist::logging::getTopLogger()->error(exp.what(), "Unable to bind to console control socket", "network.local.address", Logging::Loggable(local))); + dnsdist::logging::getTopLogger("setup")->error(exp.what(), "Unable to bind to console control socket", "network.local.address", Logging::Loggable(local))); } } @@ -3547,7 +3547,7 @@ static ListeningSockets initListeningSockets() } catch (const std::exception& exp) { SLOG(errlog("Unable to bind to web server socket on %s: %s", local.toStringWithPort(), exp.what()), - dnsdist::logging::getTopLogger()->error(exp.what(), "Unable to bind to web server socket", "network.local.address", Logging::Loggable(local))); + dnsdist::logging::getTopLogger("setup")->error(exp.what(), "Unable to bind to web server socket", "network.local.address", Logging::Loggable(local))); } } @@ -3567,7 +3567,7 @@ static std::optional lookForTentativeConfigurationFileWithExtension return tentativeFile; } -static bool loadConfigurationFromFile(const std::string& configurationFile, bool isClient, bool configCheck, const std::shared_ptr& logger) +static bool loadConfigurationFromFile(const std::string& configurationFile, bool isClient, bool configCheck, const std::shared_ptr& logger) { if (boost::ends_with(configurationFile, ".yml")) { // the bindings are always needed, for example for inline Lua @@ -3630,7 +3630,7 @@ int main(int argc, char** argv) /* for now, we will create the correct backend after parsing the configuration */ dnsdist::logging::setup(""); - auto setupLogger = dnsdist::logging::getTopLogger()->withName("setup"); + auto setupLogger = dnsdist::logging::getTopLogger("setup"); openlog("dnsdist", LOG_PID | LOG_NDELAY, LOG_DAEMON); @@ -3664,7 +3664,7 @@ int main(int argc, char** argv) if (cmdLine.useStructuredLogging && !cmdLine.structuredLoggingBackend.empty()) { dnsdist::logging::setup(cmdLine.structuredLoggingBackend); - setupLogger = dnsdist::logging::getTopLogger()->withName("setup"); + setupLogger = dnsdist::logging::getTopLogger("setup"); } dnsdist::configuration::updateRuntimeConfiguration([](dnsdist::configuration::RuntimeConfiguration& config) { @@ -3717,7 +3717,7 @@ int main(int argc, char** argv) } // No exception was thrown dnsdist::logging::setup(dnsdist::configuration::getImmutableConfiguration().d_loggingBackend); - setupLogger = dnsdist::logging::getTopLogger()->withName("setup"); + setupLogger = dnsdist::logging::getTopLogger("setup"); SLOG(infolog("Configuration '%s' OK!", cmdLine.config), setupLogger->info(Logr::Info, "Configuration OK", "path", Logging::Loggable(cmdLine.config))); @@ -3741,7 +3741,7 @@ int main(int argc, char** argv) } dnsdist::logging::setup(dnsdist::configuration::getImmutableConfiguration().d_loggingBackend); - setupLogger = dnsdist::logging::getTopLogger()->withName("setup"); + setupLogger = dnsdist::logging::getTopLogger("setup"); // we only want to update this value if it has not been set by either the Lua or YAML configuration, // and we need to stop touching this value once the backends' hashes have been computed, in setupPools() @@ -3951,27 +3951,27 @@ int main(int argc, char** argv) catch (const LuaContext::ExecutionErrorException& e) { try { SLOG(errlog("Fatal Lua error: %s", e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Error, e.what(), "Fatal Lua error")); + dnsdist::logging::getTopLogger("main")->error(Logr::Error, e.what(), "Fatal Lua error")); std::rethrow_if_nested(e); } catch (const std::exception& ne) { SLOG(errlog("Details: %s", ne.what()), - dnsdist::logging::getTopLogger()->error(Logr::Error, ne.what(), "Additional details for fatal Lua error")); + dnsdist::logging::getTopLogger("main")->error(Logr::Error, ne.what(), "Additional details for fatal Lua error")); } catch (const PDNSException& ae) { SLOG(errlog("Fatal pdns error: %s", ae.reason), - dnsdist::logging::getTopLogger()->error(Logr::Error, ae.reason, "Additional PowerDNS details for fatal Lua error")); + dnsdist::logging::getTopLogger("main")->error(Logr::Error, ae.reason, "Additional PowerDNS details for fatal Lua error")); } doExitNicely(EXIT_FAILURE); } catch (const std::exception& e) { SLOG(errlog("Fatal error: %s", e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Error, e.what(), "Fatal error")); + dnsdist::logging::getTopLogger("main")->error(Logr::Error, e.what(), "Fatal error")); doExitNicely(EXIT_FAILURE); } catch (const PDNSException& ae) { SLOG(errlog("Fatal pdns error: %s", ae.reason), - dnsdist::logging::getTopLogger()->error(Logr::Error, ae.reason, "Fatal PowerDNS error")); + dnsdist::logging::getTopLogger("main")->error(Logr::Error, ae.reason, "Fatal PowerDNS error")); doExitNicely(EXIT_FAILURE); } } diff --git a/pdns/dnsdistdist/doh3.cc b/pdns/dnsdistdist/doh3.cc index 153b3e73b6..ec7eb80428 100644 --- a/pdns/dnsdistdist/doh3.cc +++ b/pdns/dnsdistdist/doh3.cc @@ -432,12 +432,12 @@ static void sendBackDOH3Unit(DOH3UnitUniquePtr&& unit, const char* description) if (!unit->dsc->d_responseSender.send(std::move(unit))) { ++dnsdist::metrics::g_stats.doh3ResponsePipeFull; VERBOSESLOG(infolog("Unable to pass a %s to the DoH3 worker thread because the pipe is full", description), - dnsdist::logging::getTopLogger()->info(Logr::Info, std::string("Unable to pass a ") + std::string(description) + " to the DoH3 worker thread because the pipe is full")); + dnsdist::logging::getTopLogger("doh3")->info(Logr::Info, std::string("Unable to pass a ") + std::string(description) + " to the DoH3 worker thread because the pipe is full")); } } catch (const std::exception& e) { VERBOSESLOG(infolog("Unable to pass a %s to the DoH3 worker thread because we couldn't write to the pipe: %s", description, e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Info, e.what(), std::string("Unable to pass a ") + std::string(description) + " to the DoH3 worker thread because we couldn't write to the pipe")); + dnsdist::logging::getTopLogger("doh3")->error(Logr::Info, e.what(), std::string("Unable to pass a ") + std::string(description) + " to the DoH3 worker thread because we couldn't write to the pipe")); } } @@ -1009,7 +1009,7 @@ void doh3Thread(ClientState* clientState) { try { std::shared_ptr& frontend = clientState->doh3Frontend; - auto frontendLogger = dnsdist::logging::getTopLogger()->withName("doh3-frontend")->withValues("frontend.address", Logging::Loggable(clientState->local)); + auto frontendLogger = dnsdist::logging::getTopLogger("doh3-frontend")->withValues("frontend.address", Logging::Loggable(clientState->local)); frontend->d_server_config->clientState = clientState; frontend->d_server_config->df = clientState->doh3Frontend; diff --git a/pdns/dnsdistdist/doq-common.cc b/pdns/dnsdistdist/doq-common.cc index 9df896a0b7..8236a14a0b 100644 --- a/pdns/dnsdistdist/doq-common.cc +++ b/pdns/dnsdistdist/doq-common.cc @@ -64,7 +64,7 @@ PacketBuffer mintToken(const PacketBuffer& dcid, const ComboAddress& peer) } catch (const std::exception& exp) { VERBOSESLOG(infolog("Error while minting DoH3 token: %s", exp.what()), - dnsdist::logging::getTopLogger()->error(Logr::Info, exp.what(), "Error while minting DoH3 token")); + dnsdist::logging::getTopLogger("doh3")->error(Logr::Info, exp.what(), "Error while minting DoH3 token")); throw; } } @@ -123,7 +123,7 @@ std::optional validateToken(const PacketBuffer& token, const Combo } catch (const std::exception& exp) { VERBOSESLOG(infolog("Error while validating DoH3 token: %s", exp.what()), - dnsdist::logging::getTopLogger()->error(Logr::Info, exp.what(), "Error while validating DoH3 token")); + dnsdist::logging::getTopLogger("doh3")->error(Logr::Info, exp.what(), "Error while validating DoH3 token")); return std::nullopt; } } @@ -149,7 +149,7 @@ static void sendFromTo(Socket& sock, const ComboAddress& peer, const ComboAddres if (ret < 0) { auto error = errno; VERBOSESLOG(infolog("Error while sending QUIC datagram of size %d to %s: %s", buffer.size(), peer.toStringWithPort(), stringerror(error)), - dnsdist::logging::getTopLogger()->error(Logr::Info, error, "Error while sending QUIC datagram", "datagram_size", Logging::Loggable(buffer.size()), "client.address", Logging::Loggable(peer))); + dnsdist::logging::getTopLogger("quic-send-from-to")->error(Logr::Info, error, "Error while sending QUIC datagram", "datagram_size", Logging::Loggable(buffer.size()), "client.address", Logging::Loggable(peer))); } return; } @@ -159,7 +159,7 @@ static void sendFromTo(Socket& sock, const ComboAddress& peer, const ComboAddres } catch (const std::exception& exp) { VERBOSESLOG(infolog("Error while sending QUIC datagram of size %d from %s to %s: %s", buffer.size(), local.toStringWithPort(), peer.toStringWithPort(), exp.what()), - dnsdist::logging::getTopLogger()->error(Logr::Info, exp.what(), "Error while sending QUIC datagram", "datagram_size", Logging::Loggable(buffer.size()), "source.address", Logging::Loggable(local), "client.address", Logging::Loggable(peer))); + dnsdist::logging::getTopLogger("quic-send-from-to")->error(Logr::Info, exp.what(), "Error while sending QUIC datagram", "datagram_size", Logging::Loggable(buffer.size()), "source.address", Logging::Loggable(local), "client.address", Logging::Loggable(peer))); } } diff --git a/pdns/dnsdistdist/doq.cc b/pdns/dnsdistdist/doq.cc index ba6177628f..d2808cff07 100644 --- a/pdns/dnsdistdist/doq.cc +++ b/pdns/dnsdistdist/doq.cc @@ -342,12 +342,12 @@ static void sendBackDOQUnit(DOQUnitUniquePtr&& unit, const char* description) if (!unit->dsc->d_responseSender.send(std::move(unit))) { ++dnsdist::metrics::g_stats.doqResponsePipeFull; VERBOSESLOG(infolog("Unable to pass a %s to the DoQ worker thread because the pipe is full", description), - dnsdist::logging::getTopLogger()->info(Logr::Info, std::string("Unable to pass a ") + std::string(description) + " to the DoQ worker thread because the pipe is full")); + dnsdist::logging::getTopLogger("doq")->info(Logr::Info, std::string("Unable to pass a ") + std::string(description) + " to the DoQ worker thread because the pipe is full")); } } catch (const std::exception& e) { VERBOSESLOG(infolog("Unable to pass a %s to the DoQ worker thread because we couldn't write to the pipe: %s", description, e.what()), - dnsdist::logging::getTopLogger()->error(Logr::Info, e.what(), std::string("Unable to pass a ") + std::string(description) + " to the DoQ worker thread because we couldn't write to the pipe")); + dnsdist::logging::getTopLogger("doq")->error(Logr::Info, e.what(), std::string("Unable to pass a ") + std::string(description) + " to the DoQ worker thread because we couldn't write to the pipe")); } } @@ -796,7 +796,7 @@ void doqThread(ClientState* clientState) { try { std::shared_ptr& frontend = clientState->doqFrontend; - auto frontendLogger = dnsdist::logging::getTopLogger()->withName("doq-frontend")->withValues("frontend.address", Logging::Loggable(clientState->local)); + auto frontendLogger = dnsdist::logging::getTopLogger("doq-frontend")->withValues("frontend.address", Logging::Loggable(clientState->local)); frontend->d_server_config->clientState = clientState; frontend->d_server_config->df = clientState->doqFrontend; diff --git a/pdns/dnsdistdist/test-dnsdistnghttp2-in_cc.cc b/pdns/dnsdistdist/test-dnsdistnghttp2-in_cc.cc index b8a1f243d4..ee319bf368 100644 --- a/pdns/dnsdistdist/test-dnsdistnghttp2-in_cc.cc +++ b/pdns/dnsdistdist/test-dnsdistnghttp2-in_cc.cc @@ -267,7 +267,7 @@ private: } catch (const std::exception& e) { SLOG(infolog("Error parsing the status header for stream ID %d: %s", frame->hd.stream_id, e.what()), - dnsdist::logging::getTopLogger()->error(e.what(), "Error parsing the status header for stream", "http.stream_id", Logging::Loggable(frame->hd.stream_id))); + dnsdist::logging::getTopLogger("nghttp2-incoming-unit-tests")->error(e.what(), "Error parsing the status header for stream", "http.stream_id", Logging::Loggable(frame->hd.stream_id))); return NGHTTP2_ERR_CALLBACK_FAILURE; } } diff --git a/pdns/remote_logger.cc b/pdns/remote_logger.cc index 979e0c9af1..064450e1ef 100644 --- a/pdns/remote_logger.cc +++ b/pdns/remote_logger.cc @@ -139,7 +139,7 @@ bool RemoteLogger::reconnect() g_slog->withName("protobuf")->error(Logr::Error, e.what(), "Exception while connecting to remote logger", "address", Logging::Loggable(d_remote))); #else SLOG(warnlog("Error connecting to remote logger %s: %s", d_remote.toStringWithPort(), e.what()), - dnsdist::logging::getTopLogger()->withName("protobuf")->error(e.what(), "Exception while connecting to remote logger", "address", Logging::Loggable(d_remote)) + dnsdist::logging::getTopLogger("protobuf")->error(e.what(), "Exception while connecting to remote logger", "address", Logging::Loggable(d_remote)) ); #endif @@ -254,7 +254,7 @@ void RemoteLogger::maintenanceThread() g_slog->withName("protobuf")->error(Logr::Error, e.what(), "Remote Logger's maintenance thread died")); #else SLOG(errlog("Remote Logger's maintenance thread died on: %s", e.what()), - dnsdist::logging::getTopLogger()->withName("protobuf")->error(e.what(), "Remote Logger's maintenance thread died") + dnsdist::logging::getTopLogger("protobuf")->error(e.what(), "Remote Logger's maintenance thread died") ); #endif } @@ -264,7 +264,7 @@ void RemoteLogger::maintenanceThread() g_slog->withName("protobuf")->info(Logr::Error, "Remote Logger's maintenance thread died")); #else SLOG(errlog("Remote Logger's maintenance thread died on: %s"), - dnsdist::logging::getTopLogger()->withName("protobuf")->info(Logr::Error, "Remote Logger's maintenance thread died") + dnsdist::logging::getTopLogger("protobuf")->info(Logr::Error, "Remote Logger's maintenance thread died") ); #endif } diff --git a/pdns/tcpiohandler.cc b/pdns/tcpiohandler.cc index 0138655824..dfd770b83c 100644 --- a/pdns/tcpiohandler.cc +++ b/pdns/tcpiohandler.cc @@ -71,7 +71,7 @@ public: for (const auto& warning : warnings) { #if defined(DNSDIST) SLOG(warnlog("%s", warning), - dnsdist::logging::getTopLogger()->info(Logr::Warning, warning)); + dnsdist::logging::getTopLogger("openssl-frontend")->info(Logr::Warning, warning)); #else /* DNSDIST */ warnlog("%s", warning); #endif /* DNSDIST */ @@ -162,7 +162,7 @@ public: if (!d_conn) { VERBOSESLOG(infolog("Error creating TLS object"), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Error creating server-side TLS object")); + dnsdist::logging::getTopLogger("openssl-server-side")->info(Logr::Info, "Error creating server-side TLS object")); if (shouldDoVerboseLogging()) { ERR_print_errors_fp(stderr); } @@ -183,7 +183,7 @@ public: if (!d_conn) { VERBOSESLOG(infolog("Error creating TLS object"), - dnsdist::logging::getTopLogger()->info(Logr::Info, "Error creating client-side TLS object")); + dnsdist::logging::getTopLogger("openssl-client-side")->info(Logr::Info, "Error creating client-side TLS object")); if (shouldDoVerboseLogging()) { ERR_print_errors_fp(stderr); } @@ -839,7 +839,7 @@ public: #if (OPENSSL_VERSION_NUMBER < 0x10002000L) #if defined(DNSDIST) SLOG(warnlog("TLS hostname validation requested but not supported for OpenSSL < 1.0.2"), - dnsdist::logging::getTopLogger()->info(Logr::Warning, "TLS hostname validation requested but not supported for OpenSSL < 1.0.2")); + dnsdist::logging::getTopLogger("openssl-client-side")->info(Logr::Warning, "TLS hostname validation requested but not supported for OpenSSL < 1.0.2")); #else /* DNSDIST */ warnlog("TLS hostname validation requested but not supported for OpenSSL < 1.0.2"); #endif /* DNSDIST */ @@ -1456,7 +1456,7 @@ public: return IOState::NeedWrite; } VERBOSESLOG(infolog("Warning, non-fatal error while writing to TLS connection: %s", gnutls_strerror(res)), - dnsdist::logging::getTopLogger()->error(Logr::Info, gnutls_strerror(res), "Non-fatal error while writing to TLS connection", "tls.provider", Logging::Loggable("GnuTLS"))); + dnsdist::logging::getTopLogger("gnutls")->error(Logr::Info, gnutls_strerror(res), "Non-fatal error while writing to TLS connection", "tls.provider", Logging::Loggable("GnuTLS"))); } } while (pos < toWrite); @@ -1493,7 +1493,7 @@ public: return IOState::NeedRead; } VERBOSESLOG(infolog("Warning, non-fatal error while writing to TLS connection: %s", gnutls_strerror(res)), - dnsdist::logging::getTopLogger()->error(Logr::Info, gnutls_strerror(res), "Non-fatal error while writing to TLS connection", "tls.provider", Logging::Loggable("GnuTLS"))); + dnsdist::logging::getTopLogger("gnutls")->error(Logr::Info, gnutls_strerror(res), "Non-fatal error while writing to TLS connection", "tls.provider", Logging::Loggable("GnuTLS"))); } } while (pos < toRead); @@ -1532,7 +1532,7 @@ public: } else { VERBOSESLOG(infolog("Non-fatal error while reading from TLS connection: %s", gnutls_strerror(res)), - dnsdist::logging::getTopLogger()->error(Logr::Info, gnutls_strerror(res), "Non-fatal error while reading from TLS connection", "tls.provider", Logging::Loggable("GnuTLS"))); + dnsdist::logging::getTopLogger("gnutls")->error(Logr::Info, gnutls_strerror(res), "Non-fatal error while reading from TLS connection", "tls.provider", Logging::Loggable("GnuTLS"))); } } @@ -1576,7 +1576,7 @@ public: } else { VERBOSESLOG(infolog("Non-fatal error while writing to TLS connection: %s", gnutls_strerror(res)), - dnsdist::logging::getTopLogger()->error(Logr::Info, gnutls_strerror(res), "Non-fatal error while writing to TLS connection", "tls.provider", Logging::Loggable("GnuTLS"))); + dnsdist::logging::getTopLogger("gnutls")->error(Logr::Info, gnutls_strerror(res), "Non-fatal error while writing to TLS connection", "tls.provider", Logging::Loggable("GnuTLS"))); } } } @@ -1761,7 +1761,7 @@ public: if (rc != GNUTLS_E_SUCCESS) { #if defined(DNSDIST) SLOG(warnlog("Error loading OCSP response from file '%s' for certificate ('%s') and key ('%s') for TLS context on %s: %s", file, frontend.d_tlsConfig.d_certKeyPairs.at(count).d_cert, frontend.d_tlsConfig.d_certKeyPairs.at(count).d_key.value(), frontend.d_addr.toStringWithPort(), gnutls_strerror(rc)), - dnsdist::logging::getTopLogger()->error(Logr::Warning, gnutls_strerror(rc), "Error loading OCSP response for TLS context", "tls.provider", Logging::Loggable("GnuTLS"), "frontend.address", Logging::Loggable(frontend.d_addr), "tls.ocsp_file", Logging::Loggable(file), "tls.certificate_file", Logging::Loggable(frontend.d_tlsConfig.d_certKeyPairs.at(count).d_cert), "tls.key_file", Logging::Loggable(frontend.d_tlsConfig.d_certKeyPairs.at(count).d_key.value()))); + dnsdist::logging::getTopLogger("gnutls")->error(Logr::Warning, gnutls_strerror(rc), "Error loading OCSP response for TLS context", "tls.provider", Logging::Loggable("GnuTLS"), "frontend.address", Logging::Loggable(frontend.d_addr), "tls.ocsp_file", Logging::Loggable(file), "tls.certificate_file", Logging::Loggable(frontend.d_tlsConfig.d_certKeyPairs.at(count).d_cert), "tls.key_file", Logging::Loggable(frontend.d_tlsConfig.d_certKeyPairs.at(count).d_key.value()))); #else /* DNSDIST */ warnlog("Error loading OCSP response from file '%s' for certificate ('%s') and key ('%s') for TLS context on %s: %s", file, frontend.d_tlsConfig.d_certKeyPairs.at(count).d_cert, frontend.d_tlsConfig.d_certKeyPairs.at(count).d_key.value(), frontend.d_addr.toStringWithPort(), gnutls_strerror(rc)); #endif /* DNSDIST */ diff --git a/pdns/threadname.cc b/pdns/threadname.cc index 25e9efb9a2..0144416940 100644 --- a/pdns/threadname.cc +++ b/pdns/threadname.cc @@ -72,7 +72,7 @@ void setThreadName(const std::string& threadName) { if (retval != 0) { #ifdef DNSDIST SLOG(warnlog("Could not set thread name %s for thread: %s", threadName, strerror(retval)), - dnsdist::logging::getTopLogger()->withName("runtime")->error(Logr::Warning, retval, "Could not set thread name", "name", Logging::Loggable(threadName))); + dnsdist::logging::getTopLogger("runtime")->error(Logr::Warning, retval, "Could not set thread name", "name", Logging::Loggable(threadName))); #else SLOG(g_log<withName("runtime")->error(Logr::Warning, retval, "Could not set thread name", "name", Logging::Loggable(threadName)));