]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Ensure we always have a structured logging subsystem set
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 15 Jan 2026 15:26:01 +0000 (16:26 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 19 Jan 2026 10:01:43 +0000 (11:01 +0100)
Signed-off-by: Remi Gacogne <remi.gacogne@powerdns.com>
47 files changed:
pdns/dnsdistdist/bpf-filter.cc
pdns/dnsdistdist/dnscrypt.cc
pdns/dnsdistdist/dnsdist-actions-factory.cc
pdns/dnsdistdist/dnsdist-async.cc
pdns/dnsdistdist/dnsdist-backend.cc
pdns/dnsdistdist/dnsdist-carbon.cc
pdns/dnsdistdist/dnsdist-concurrent-connections.cc
pdns/dnsdistdist/dnsdist-configuration-yaml.cc
pdns/dnsdistdist/dnsdist-console.cc
pdns/dnsdistdist/dnsdist-discovery.cc
pdns/dnsdistdist/dnsdist-dnscrypt.cc
pdns/dnsdistdist/dnsdist-dynblocks.cc
pdns/dnsdistdist/dnsdist-healthchecks.cc
pdns/dnsdistdist/dnsdist-idstate.cc
pdns/dnsdistdist/dnsdist-kvs.cc
pdns/dnsdistdist/dnsdist-lbpolicies.cc
pdns/dnsdistdist/dnsdist-logging.cc
pdns/dnsdistdist/dnsdist-logging.hh
pdns/dnsdistdist/dnsdist-lua-bindings-dnscrypt.cc
pdns/dnsdistdist/dnsdist-lua-bindings-network.cc
pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc
pdns/dnsdistdist/dnsdist-lua-bindings.cc
pdns/dnsdistdist/dnsdist-lua-configuration-items.cc
pdns/dnsdistdist/dnsdist-lua-ffi.cc
pdns/dnsdistdist/dnsdist-lua-hooks.cc
pdns/dnsdistdist/dnsdist-lua-inspection.cc
pdns/dnsdistdist/dnsdist-lua-network.cc
pdns/dnsdistdist/dnsdist-lua-rules.cc
pdns/dnsdistdist/dnsdist-lua.cc
pdns/dnsdistdist/dnsdist-lua.hh
pdns/dnsdistdist/dnsdist-nghttp2.cc
pdns/dnsdistdist/dnsdist-protobuf.cc
pdns/dnsdistdist/dnsdist-proxy-protocol.cc
pdns/dnsdistdist/dnsdist-secpoll.cc
pdns/dnsdistdist/dnsdist-snmp.cc
pdns/dnsdistdist/dnsdist-tcp-downstream.cc
pdns/dnsdistdist/dnsdist-tcp.cc
pdns/dnsdistdist/dnsdist-web.cc
pdns/dnsdistdist/dnsdist-xsk.cc
pdns/dnsdistdist/dnsdist.cc
pdns/dnsdistdist/doh3.cc
pdns/dnsdistdist/doq-common.cc
pdns/dnsdistdist/doq.cc
pdns/dnsdistdist/test-dnsdistnghttp2-in_cc.cc
pdns/remote_logger.cc
pdns/tcpiohandler.cc
pdns/threadname.cc

index f4f64d0ae42b01e222e638b4228ba77f326c13ad..b279dbf5ceaa21c8c81e2e8a285dda09a7f6618f 100644 (file)
@@ -367,7 +367,7 @@ BPFFilter::BPFFilter(std::unordered_map<std::string, MapConfiguration>& 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<std::string, MapConfiguration>& 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)));
     }
   }
 
index 95892c14ecb450971f739d6336dcdf61c2a7a7a3..40823e2c969700ae81867306a9a8cf0dbd86d672 100644 (file)
@@ -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());
index d2753a5e7b9692cc8b94f015b7fe2c54270b5308..8fa0e6fc6f0c056ba637b4a3b25c4f49b38ba285 100644 (file)
@@ -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())));
   }
 }
 
index 9cf8f9a8a31bab9b37f133c274469e162f2797b0..8bd0caa46e66bfc16bf2c67a5a3a0db3460f3554 100644 (file)
@@ -136,7 +136,7 @@ void AsynchronousHolder::mainThread(std::shared_ptr<Data> 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> 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<CrossProtocolQuery> 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<CrossProtocolQuery>&& 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<CrossProtocolQuery>&& 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;
   }
 
index a0aa1bd75cfa4b14b318ebed7ad474a415be9240..9e5f2c075ed5b222de0f8bf9182c8f31638d7ef3 100644 (file)
@@ -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<const Logr::Logger> 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
index 0364eeea1972699803ef3999089d6669660e532e..3bad273103c274edd96006f487bfc670b738ef08 100644 (file)
@@ -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 */
index 935c4fa8d9cb0770004271c05d7d023beeb66ca5..eeb277081e72d212f15ab3afdcc82f62b913a3f1 100644 (file)
@@ -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<void(const ClientEntry& entry)>& callback)
index 5ca65eed1fa6c30d4227f591ee34c08845e92790..16787b48a482f3ce4ea720c60dc12a227878b13f 100644 (file)
@@ -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,
   };
index 9034bb3c574fd15bdaa452dcb88da553aaa95235..df452b0f0ff4e22eed22e38f35b78ba2cd31ef06 100644 (file)
@@ -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"));
index da1904c100d22158c7a4b0eccaf28d78420e947f..6c6321bd2b29e119fa1b18ab9e5602c73d716d2e 100644 (file)
@@ -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();
index ac1196fde4de5d9e0d9340a9c44285727d355de5..e143189dfd19826a75540415db6c430dbb91ecfe 100644 (file)
@@ -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;
   }
 
index 6c0122dbea9eff3768d1b575bfc116213a34ecdc..a9d86d9a2b4c96031669269c5cfc4b59a68f663f 100644 (file)
@@ -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::optional<ClientAddressDynamicRul
     }
     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 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"));
     }
   }
 }
index b0ed0999d633bfe2c54a4393296c9392dcbcfd6f..8dcc175dc9f280d6acfe5f069b96455c0efd3a08 100644 (file)
@@ -74,7 +74,7 @@ static void updateLatencyMetrics(DownstreamState& downstream, int elapsed /* mic
 static std::shared_ptr<Logr::Logger> getLoggerFromData(const std::shared_ptr<const HealthCheckData>& 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<HealthCheckData>& data)
@@ -356,7 +356,7 @@ bool queueHealthCheck(std::unique_ptr<FDMultiplexer>& mplexer, const std::shared
   const auto verboseHealthChecks = dnsdist::configuration::getCurrentRuntimeConfiguration().d_verboseHealthChecks;
   std::shared_ptr<Logr::Logger> 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<FDMultiplexer>& mplexer, const std::shared
 void handleQueuedHealthChecks(FDMultiplexer& mplexer, bool initial)
 {
   const auto verboseHealthChecks = dnsdist::configuration::getCurrentRuntimeConfiguration().d_verboseHealthChecks;
-  std::shared_ptr<Logr::Logger> logger;
+  std::shared_ptr<const Logr::Logger> 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) {
index 9855dfe898f1b919506e2b811ea4954e0ffc166f..f9e21983be61fad0c48cf0057e2a3bc42307468d 100644 (file)
@@ -167,7 +167,7 @@ std::optional<pdns::trace::dnsdist::Tracer::Closer> InternalQueryState::getRules
 std::shared_ptr<const Logr::Logger> InternalQueryState::getLogger(std::shared_ptr<const Logr::Logger> 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;
index 465595dbe2e711de0470e909d2f41faeccb3e675..ff2b1a0af378d301353470e26f346adcafc81b00 100644 (file)
@@ -83,7 +83,7 @@ std::vector<std::string> KeyValueLookupKeySuffix::getKeys(const DNSName& qname)
 #ifdef HAVE_LMDB
 std::shared_ptr<const Logr::Logger> 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<const Logr::Logger> 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)
index 35975f9ecb58f8e7cc82555633d2fbaa1a3e0c95..8e2b3eec5ef4997445725cf0b8b3188cea5b0723 100644 (file)
@@ -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<ServerPolicy> 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<DownstreamState> 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_ptr<DownstreamStat
 {
   if (!poolName.empty()) {
     VERBOSESLOG(infolog("Removing server from pool %s", poolName),
-                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)));
   }
   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) {
index ce6237395f6811afec16f289d63ee364688be8d0..5b007a523e41908e02a527ce73dcab19e7c3c8bd 100644 (file)
@@ -213,14 +213,14 @@ void setup(const std::string& backend)
   }
 }
 
-std::shared_ptr<const Logr::Logger> getTopLogger()
+std::shared_ptr<const Logr::Logger> 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()
index 29a78b1775bebb5eb6e14ab69a024ab79405ce17..bdcad234713ecd60cee17b244bebc7e6ff8cd7aa 100644 (file)
 
 #include <memory>
 #include <string>
+#include <string_view>
 
 #include "logging.hh"
 
 namespace dnsdist::logging
 {
 void setup(const std::string& backend);
-std::shared_ptr<const Logr::Logger> getTopLogger();
+std::shared_ptr<const Logr::Logger> getTopLogger(const std::string_view& subsystem);
 bool doVerboseLogging();
 bool doStructuredLogging();
 }
index 28460c5e3666287ea7218a3e1c9f281405751973..cb39a2eff3b8748a605e68c44e14e0094dc8f561 100644 (file)
@@ -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";
     }
   });
index e782a1996134b84ad7fcf69661daa7fe29a59036..856158cfc76f272a5fc21f7eedfe74c0f286726a 100644 (file)
@@ -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<dnsdist::NetworkEndpoint>(nullptr);
   });
index f3b20115b700c6f354f8bb9e7f10e8c39f1bfe7d..b772a511614e4c1f69952f871b7a23993e127e8d 100644 (file)
@@ -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;
     }
index 953d80aeedf946dcf7a8a89953c949b9b7a7f6ad..97c1a4a4d5fb4b5f9658f02e8fa1876eac707c7f 100644 (file)
@@ -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
index 1a4afe5989ec17ef29f755d0ec4d567884182e5c..4e56f071ab2eb53baa857690285fb804f75ffddc 100644 (file)
@@ -101,14 +101,14 @@ static const std::map<std::string, UnsignedIntegerConfigurationItems> 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();
     });
index 86f8f8f1a572c250c0ce694f3773212f1767b260..ac1512d3a15eb3b8b45e709bfb11914651b425a4 100644 (file)
@@ -40,7 +40,7 @@
 
 static std::shared_ptr<const Logr::Logger> 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)
index bef83c2af8992da454fcf000743fb06e94254be5..7080f0cd6b4cf5eea946c5d370af5f450dc99185 100644 (file)
@@ -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"));
     }
   });
 }
index 9d36b90498c1091c31792eec97a1ceef6f8a992c..22bf3c8c70bab0f0ac9ea6723287cad4e5644930 100644 (file)
@@ -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;
                            }
                          }
index da3731bee504fe06861e4826a50ab25c8c439b5f..95af07beb87f3e3fb7b24d3cfe273d6ee5f91b06 100644 (file)
@@ -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)));
       }
     }
   }
index 8d841a10e8a61ccfcbd9ce99691d4efe5c6493ef..8fbc3388aea11f5f1158a8cd078fb0a49fecef27 100644 (file)
@@ -69,7 +69,7 @@ std::shared_ptr<DNSRule> 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<NetmaskGroupRule>(nmg, true);
 }
index 03d613628ea643ca9b12a64dd6a53da7a2b0cdbc..f4b4e5e0c9a620448801d6f8acf5aac7b7f5cdd6 100644 (file)
@@ -122,7 +122,7 @@ void resetLuaSideEffect()
 
 static std::shared_ptr<const Logr::Logger> 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);
index f888eef0bd79fe5803e85672ef0e0c0fcbc2a50a..8851fff5ec58b32b0450f5e8ba03fcb993a23d10 100644 (file)
@@ -82,7 +82,7 @@ std::optional<FunctionType> 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<V>& 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")));
   }
 }
index 855ab63ea474d8dcb1c480c131864fe2a36b2ed4..be53ce1970a678e73b3711fec58151ec6c3e6b4d 100644 (file)
@@ -899,7 +899,7 @@ static void handleCrossProtocolQuery(int pipefd, FDMultiplexer::funcparam_t& par
 static void dohClientThread(pdns::channel::Receiver<CrossProtocolQuery>&& 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<CrossProtocolQuery>(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 */
index a4423a55222f414094f91ad378ac449d99f3dbeb..6559cfa45487219d0cc3aa58ab5090889e20bd6f 100644 (file)
@@ -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 {
index c2ae7c0564ce0205c738dec2bf3093ef6622f302..4f44a5bd88015269d9f60f7451b542aadaae1b10 100644 (file)
@@ -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<size_t>(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;
     }
index c618cd308a7727368b2a68d1825f205f916d1c42..9b13502882bd028332071ab649e82b1aa29cc061 100644 (file)
@@ -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);
index 1a5ebd705c9b4ffb25f308b35036fe9ebf2ed737..77791772d25cc08690aef63781b40b9bed13f31e 100644 (file)
@@ -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;
   }
 
index 18fd9bb59d91d819fbe647ac67490e8c388edbf4..8548b072b3a97f7476b8cffa682203da53f188f9 100644 (file)
@@ -917,7 +917,7 @@ bool TCPConnectionToBackend::isXFRFinished(const TCPResponse& response, TCPQuery
 
 std::shared_ptr<const Logr::Logger> 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()));
   }
index 0c0148fb13f76e54b6d28ffc3b837a9f41654582..01c410473e64692b7912c5169aac70b9e7fa62ee 100644 (file)
@@ -194,11 +194,11 @@ void TCPClientCollection::addTCPClientThread(std::vector<ClientState*>& tcpAccep
     auto [crossProtocolResponseChannelSender, crossProtocolResponseChannelReceiver] = pdns::channel::createObjectQueue<TCPCrossProtocolResponse>(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<ClientState*>& 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<ClientState*>& 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<IncomingTCPConnec
 
 std::shared_ptr<const Logr::Logger> 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<ConnectionInfo>&& 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);
     }
index c242be5ab67fd313cc6f36cf6fbdb990ae82b21d..5f546ce9ec421101583d27a4f16ca08131cf1cb9 100644 (file)
@@ -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"));
 
index 9531226f74d9c922adb6eac7d995d3bf3f031a07..d66b5dea221a3d07912027e470a14e95e99f6989 100644 (file)
@@ -39,7 +39,7 @@ void XskResponderThread(std::shared_ptr<DownstreamState> dss, std::shared_ptr<Xs
 {
   try {
     setThreadName("dnsdist/XskResp");
-    auto logger = dnsdist::logging::getTopLogger()->withName("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<DownstreamState> dss, std::shared_ptr<Xs
   }
   catch (const std::exception& e) {
     SLOG(errlog("XSK responder thread died because of exception: %s", e.what()),
-         dnsdist::logging::getTopLogger()->error(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<XskSocket> 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
index dbf2b6b5729c7b6295c2c078c7b43e62384a415f..5a7f41636c41a710413e4abf8de5038f3d9c818a 100644 (file)
@@ -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<size_t>(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<DownstreamState>& dss, PacketBuffer&
 // listens on a dedicated socket, lobs answers from downstream servers to original requestors
 void responderThread(std::shared_ptr<DownstreamState> 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<DownstreamState>& 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<unsigned int>(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<ClientState*> 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<Logr::Logger>& logger)
+static void bindAny([[maybe_unused]] int addressFamily, [[maybe_unused]] int sock, [[maybe_unused]] const std::shared_ptr<const Logr::Logger>& 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<Logr::Logger>& logger)
+static void setupLocalSocket(ClientState& clientState, const ComboAddress& addr, int& socket, bool tcp, bool warn, const std::shared_ptr<const Logr::Logger>& 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<Logr::Logger>& logger)
+static void setUpLocalBind(ClientState& cstate, const std::shared_ptr<const Logr::Logger>& 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<Logr::Logger>& logger)
+static void setupPools(const std::shared_ptr<const Logr::Logger>& 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<std::string> lookForTentativeConfigurationFileWithExtension
   return tentativeFile;
 }
 
-static bool loadConfigurationFromFile(const std::string& configurationFile, bool isClient, bool configCheck, const std::shared_ptr<Logr::Logger>& logger)
+static bool loadConfigurationFromFile(const std::string& configurationFile, bool isClient, bool configCheck, const std::shared_ptr<const Logr::Logger>& 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);
   }
 }
index 153b3e73b6511bb62146c5921086223d8ac1edd6..ec7eb804283a0edb5fda159987e6a72686d345a0 100644 (file)
@@ -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<DOH3Frontend>& 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;
index 9df896a0b7ff10d13b38532feaa27e692a56e151..8236a14a0b379a338c605c0354ebd27ba16d1e8a 100644 (file)
@@ -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<PacketBuffer> 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)));
   }
 }
 
index ba6177628fe639788b26c43d33952c9f4bfb2c2d..d2808cff0706fcfab5bbf990c853365cf2ecf6cb 100644 (file)
@@ -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<DOQFrontend>& 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;
index b8a1f243d4da4a58a1771a4bf7a82e3c5841132f..ee319bf3686d8cee2e6e30b5560fe0187f7ba010 100644 (file)
@@ -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;
         }
       }
index 979e0c9af1a9ebdc79b8adaf68f7d73c08c36147..064450e1ef3e399588af0db0187548a057dd3737 100644 (file)
@@ -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
   }
index 0138655824ba45cb3fd7cc75a99518ad469cf756..dfd770b83c3c9bdee3b925ad0e3cd082d7e4b1e0 100644 (file)
@@ -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 */
index 25e9efb9a2b08c18d1da4661c8ccf91bcaa23bcf..0144416940c713419b68dec41beb187c4884cc73 100644 (file)
@@ -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<<Logger::Warning<<"Could not set thread name "<<threadName<<" for thread: "<<strerror(retval)<<endl,
          g_slog->withName("runtime")->error(Logr::Warning, retval, "Could not set thread name", "name", Logging::Loggable(threadName)));