]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Tweaks: use name for prio, change some prio's, use setter for arguments
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 18 May 2022 11:42:27 +0000 (13:42 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 18 May 2022 12:13:15 +0000 (14:13 +0200)
pdns/arguments.hh
pdns/pdns_recursor.cc
pdns/recursordist/logr.hh
pdns/recursordist/rec-main.cc
pdns/reczones.cc
pdns/rpzloader.cc

index 96b562580c2dff5d461409641ca8a690ab95a30e..1e48ee2b79a5dd3132fe8677aa1021241a7ec002 100644 (file)
@@ -77,9 +77,6 @@ class ArgvMap
 {
 public:
   ArgvMap();
-#ifdef RECURSOR
-  std::shared_ptr<Logr::Logger> d_log;
-#endif
   void parse(int &argc, char **argv, bool lax=false); //!< use this to parse from argc and argv
   void laxParse(int &argc, char **argv) //!< use this to parse from argc and argv
   {
@@ -122,6 +119,12 @@ public:
   const string &operator[](const string &); //!< iterator semantics
   const vector<string>&getCommands();
   void gatherIncludes(std::vector<std::string> &extraConfigs);
+#ifdef RECURSOR
+  void setSLog(std::shared_ptr<Logr::Logger>& log)
+  {
+    d_log = log;
+  }
+#endif
 private:
   void warnIfDeprecated(const string& var);
   void parseOne(const string &unparsed, const string &parseOnly="", bool lax=false);
@@ -133,6 +136,9 @@ private:
   map<string,string> d_typeMap;
   vector<string> d_cmds;
   std::set<string> d_cleared;
+#ifdef RECURSOR
+  std::shared_ptr<Logr::Logger> d_log;
+#endif
 };
 
 extern ArgvMap &arg();
index 55d55f9b03c8e5f13cb5406e8afd7e4dda9a73b0..5e4cdb9d8fea10556c8cb716e5049f9f0468361e 100644 (file)
@@ -2384,7 +2384,7 @@ void makeUDPServerSockets(deferredAdd_t& deferredAdds, std::shared_ptr<Logr::Log
     deferredAdds.emplace_back(fd, handleNewUDPQuestion);
     g_listenSocketsAddresses[fd] = sin; // this is written to only from the startup thread, not from the workers
     SLOG(g_log << Logger::Info << "Listening for UDP queries on " << sin.toStringWithPort() << endl,
-         log->info(Logr::Info, "Listening forqueries", "protocol", Logging::Loggable("UDP"), "address", Logging::Loggable(sin.toStringWithPort())));
+         log->info(Logr::Info, "Listening for queries", "protocol", Logging::Loggable("UDP"), "address", Logging::Loggable(sin.toStringWithPort())));
   }
 }
 
index f1ad0931c95babb3fcb7c7c79ececa016cde85f3..857cc0290bed6b01212c9ef4af336cdd0d484de8 100644 (file)
@@ -22,6 +22,7 @@
 
 #pragma once
 
+#include <array>
 #include <string>
 #include <memory>
 #include <map>
@@ -64,6 +65,15 @@ public:
   // logs.
   virtual bool enabled(Priority) const = 0;
 
+  static std::string toString(Priority arg)
+  {
+    const std::array<std::string, 8> names = {"Absent", "Alert", "Critical", "Error", "Warning", "Notice", "Info", "Debug"};
+    auto p = static_cast<unsigned int>(arg);
+    if (p >= names.size()) {
+      return "?";
+    }
+    return names.at(p);
+  }
   // Info logs a non-error message with the given key/value pairs as context.
   //
   // The msg argument should be used to add some constant description to
index be46da934b6396b2bdcb008cdf21a3f6b9c65856..9adb6a4afc3a9c7e3e4ef4fcc5491a97ce1121dd 100644 (file)
@@ -199,7 +199,7 @@ int RecThreadInfo::runThreads(std::shared_ptr<Logr::Logger>& log)
 
   if (RecThreadInfo::numDistributors() + RecThreadInfo::numWorkers() == 1) {
     SLOG(g_log << Logger::Warning << "Operating with single distributor/worker thread" << endl,
-         log->info(Logr::Warning, "Operating with single distributor/worker thread"));
+         log->info(Logr::Notice, "Operating with single distributor/worker thread"));
 
     /* This thread handles the web server, carbon, statistics and the control channel */
     auto& handlerInfo = RecThreadInfo::info(0);
@@ -245,14 +245,14 @@ int RecThreadInfo::runThreads(std::shared_ptr<Logr::Logger>& log)
     // And now start the actual threads
     if (RecThreadInfo::weDistributeQueries()) {
       SLOG(g_log << Logger::Warning << "Launching " << RecThreadInfo::numDistributors() << " distributor threads" << endl,
-           log->info(Logr::Warning, "Launching distributor threads", "count", Logging::Loggable(RecThreadInfo::numDistributors())));
+           log->info(Logr::Notice, "Launching distributor threads", "count", Logging::Loggable(RecThreadInfo::numDistributors())));
       for (unsigned int n = 0; n < RecThreadInfo::numDistributors(); ++n) {
         auto& info = RecThreadInfo::info(currentThreadId);
         info.start(currentThreadId++, "distr", cpusMap);
       }
     }
     SLOG(g_log << Logger::Warning << "Launching " << RecThreadInfo::numWorkers() << " worker threads" << endl,
-         log->info(Logr::Warning, "Launching worker threads", "count", Logging::Loggable(RecThreadInfo::numWorkers())));
+         log->info(Logr::Notice, "Launching worker threads", "count", Logging::Loggable(RecThreadInfo::numWorkers())));
 
     for (unsigned int n = 0; n < RecThreadInfo::numWorkers(); ++n) {
       auto& info = RecThreadInfo::info(currentThreadId);
@@ -850,15 +850,15 @@ static void loggerBackend(const Logging::Entry& entry)
   buf.str("");
   buf << "msg=" << std::quoted(entry.message);
   if (entry.error) {
-    buf << " oserror=" << std::quoted(entry.error.get());
+    buf << " error=" << std::quoted(entry.error.get());
   }
 
   if (entry.name) {
     buf << " subsystem=" << std::quoted(entry.name.get());
   }
-  buf << " level=" << entry.level;
+  buf << " level=" << std::quoted(std::to_string(entry.level));
   if (entry.d_priority) {
-    buf << " prio=" << static_cast<int>(entry.d_priority);
+    buf << " prio=" << std::quoted(Logr::Logger::toString(entry.d_priority));
   }
   char timebuf[64];
   buf << " ts=" << std::quoted(toTimestampStringMilli(entry.d_timestamp, timebuf, sizeof(timebuf)));
@@ -1216,7 +1216,7 @@ static int serviceMain(int argc, char* argv[], std::shared_ptr<Logr::Logger>& lo
   if (pdns::isQueryLocalAddressFamilyEnabled(AF_INET)) {
     SyncRes::s_doIPv4 = true;
     SLOG(g_log << Logger::Warning << "Enabling IPv4 transport for outgoing queries" << endl,
-         log->info(Logr::Warning, "Enabling IPv4 transport for outgoing queries"));
+         log->info(Logr::Notice, "Enabling IPv4 transport for outgoing queries"));
   }
   else {
     SLOG(g_log << Logger::Warning << "NOT using IPv4 for outgoing queries - add an IPv4 address (like '0.0.0.0') to query-local-address to enable" << endl,
@@ -1226,7 +1226,7 @@ static int serviceMain(int argc, char* argv[], std::shared_ptr<Logr::Logger>& lo
   if (pdns::isQueryLocalAddressFamilyEnabled(AF_INET6)) {
     SyncRes::s_doIPv6 = true;
     SLOG(g_log << Logger::Warning << "Enabling IPv6 transport for outgoing queries" << endl,
-         log->info(Logr::Warning, "Enabling IPv6 transport for outgoing queries"));
+         log->info(Logr::Notice, "Enabling IPv6 transport for outgoing queries"));
   }
   else {
     SLOG(g_log << Logger::Warning << "NOT using IPv6 for outgoing queries - add an IPv6 address (like '::') to query-local-address to enable" << endl,
@@ -1304,7 +1304,7 @@ static int serviceMain(int argc, char* argv[], std::shared_ptr<Logr::Logger>& lo
       g_log << Logger::Warning << endl;
     }
     else {
-      log->info(Logr::Warning, "Will not send queries to", "addresses", Logging::Loggable(ips));
+      log->info(Logr::Notice, "Will not send queries to", "addresses", Logging::Loggable(ips));
     }
   }
 
@@ -1312,7 +1312,7 @@ static int serviceMain(int argc, char* argv[], std::shared_ptr<Logr::Logger>& lo
   RecThreadInfo::setWeDistributeQueries(::arg().mustDo("pdns-distributes-queries"));
   if (RecThreadInfo::weDistributeQueries()) {
     SLOG(g_log << Logger::Warning << "PowerDNS Recursor itself will distribute queries over threads" << endl,
-         log->info(Logr::Warning, "PowerDNS Recursor itself will distribute queries over threads"));
+         log->info(Logr::Notice, "PowerDNS Recursor itself will distribute queries over threads"));
   }
 
   g_outgoingEDNSBufsize = ::arg().asNum("edns-outgoing-bufsize");
@@ -2671,9 +2671,9 @@ int main(int argc, char** argv)
 
     g_slog = Logging::Logger::create(loggerBackend);
     // Missing: a mechanism to call setVerbosity(x)
-    auto startupLog = g_slog->withName("startup");
+    auto startupLog = g_slog->withName("config");
 
-    ::arg().d_log = startupLog;
+    ::arg().setSLog(startupLog);
     if (!::arg().file(configname.c_str())) {
       SLOG(g_log << Logger::Warning << "Unable to parse configuration file '" << configname << "'" << endl,
            startupLog->error("No such file", "Unable to parse configuration file", "config_file", Logging::Loggable(configname)));
@@ -2732,17 +2732,17 @@ int main(int argc, char** argv)
   }
   catch (const PDNSException& ae) {
     SLOG(g_log << Logger::Error << "Exception: " << ae.reason << endl,
-         g_slog->withName("startup")->error(Logr::Error, ae.reason, "Exception"));
+         g_slog->withName("config")->error(Logr::Error, ae.reason, "Exception"));
     ret = EXIT_FAILURE;
   }
   catch (const std::exception& e) {
     SLOG(g_log << Logger::Error << "STL Exception: " << e.what() << endl,
-         g_slog->withName("startup")->error(Logr::Error, e.what(), "STL Exception"));
+         g_slog->withName("config")->error(Logr::Error, e.what(), "STL Exception"));
     ret = EXIT_FAILURE;
   }
   catch (...) {
     SLOG(g_log << Logger::Error << "any other exception in main: " << endl,
-         g_slog->withName("startup")->error(Logr::Error, "Unknown", "Exception"));
+         g_slog->withName("config")->error(Logr::Error, "Unknown", "Exception"));
     ret = EXIT_FAILURE;
   }
 
index bcad1a34148c6908f96b1cd89318546fa9e197e4..228e70d094fb1e40ba1a7b9def8b7de78dd2304b 100644 (file)
@@ -226,7 +226,7 @@ static void makeNameToIPZone(std::shared_ptr<SyncRes::domainmap_t> newMap, const
   }
   else {
     SLOG(g_log << Logger::Warning << "Inserting forward zone '" << dr.d_name << "' based on hosts file" << endl,
-         log->info(Logr::Warning, "Inserting forward zone based on hosts file", "zone", Logging::Loggable(dr.d_name)));
+         log->info(Logr::Notice, "Inserting forward zone based on hosts file", "zone", Logging::Loggable(dr.d_name)));
     ad.d_name = dr.d_name;
     (*newMap)[ad.d_name] = ad;
   }
@@ -275,7 +275,7 @@ static void makeIPToNamesZone(std::shared_ptr<SyncRes::domainmap_t> newMap, cons
   else {
     if (ipparts.size() == 4) {
       SLOG(g_log << Logger::Warning << "Inserting reverse zone '" << dr.d_name << "' based on hosts file" << endl,
-           log->info(Logr::Warning, "Inserting reverse zone based on hosts file", "zone", Logging::Loggable(dr.d_name)));
+           log->info(Logr::Notice, "Inserting reverse zone based on hosts file", "zone", Logging::Loggable(dr.d_name)));
     }
     ad.d_name = dr.d_name;
     (*newMap)[ad.d_name] = ad;
@@ -334,7 +334,7 @@ string reloadZoneConfiguration()
 
   try {
     SLOG(g_log << Logger::Warning << "Reloading zones, purging data from cache" << endl,
-         log->info(Logr::Warning, "Reloading zones, purging data from cache"));
+         log->info(Logr::Notice, "Reloading zones, purging data from cache"));
 
     string configname = ::arg()["config-dir"] + "/recursor.conf";
     if (::arg()["config-name"] != "") {
@@ -479,7 +479,7 @@ std::tuple<std::shared_ptr<SyncRes::domainmap_t>, std::shared_ptr<notifyset_t>>
 
   if (!::arg()["forward-zones-file"].empty()) {
     SLOG(g_log << Logger::Warning << "Reading zone forwarding information from '" << ::arg()["forward-zones-file"] << "'" << endl,
-         log->info(Logr::Warning, "Reading zone forwarding information", "file", Logging::Loggable(::arg()["forward-zones-file"])));
+         log->info(Logr::Notice, "Reading zone forwarding information", "file", Logging::Loggable(::arg()["forward-zones-file"])));
     auto fp = std::unique_ptr<FILE, int (*)(FILE*)>(fopen(::arg()["forward-zones-file"].c_str(), "r"), fclose);
     if (!fp) {
       throw PDNSException("Error opening forward-zones-file '" + ::arg()["forward-zones-file"] + "': " + stringerror());
@@ -537,7 +537,7 @@ std::tuple<std::shared_ptr<SyncRes::domainmap_t>, std::shared_ptr<notifyset_t>>
       }
     }
     SLOG(g_log << Logger::Warning << "Done parsing " << newMap->size() - before << " forwarding instructions from file '" << ::arg()["forward-zones-file"] << "'" << endl,
-         log->info(Logr::Warning, "Done parsing forwarding instructions from file", "file", Logging::Loggable(::arg()["forward-zones-file"]), "count", Logging::Loggable(newMap->size() - before)));
+         log->info(Logr::Notice, "Done parsing forwarding instructions from file", "file", Logging::Loggable(::arg()["forward-zones-file"]), "count", Logging::Loggable(newMap->size() - before)));
   }
 
   if (::arg().mustDo("export-etc-hosts")) {
@@ -580,7 +580,7 @@ std::tuple<std::shared_ptr<SyncRes::domainmap_t>, std::shared_ptr<notifyset_t>>
 
   if (::arg().mustDo("serve-rfc1918")) {
     SLOG(g_log << Logger::Warning << "Inserting rfc 1918 private space zones" << endl,
-         log->info(Logr::Warning, "Inserting rfc 1918 private space zones"));
+         log->info(Logr::Notice, "Inserting rfc 1918 private space zones"));
     parts.clear();
     parts.push_back("127");
     makeIPToNamesZone(newMap, parts, log);
@@ -617,7 +617,7 @@ std::tuple<std::shared_ptr<SyncRes::domainmap_t>, std::shared_ptr<notifyset_t>>
       newSet->insert(DNSName(line));
     }
     SLOG(g_log << Logger::Warning << "Done parsing " << newSet->size() - before << " NOTIFY-allowed zones from file '" << anff << "'" << endl,
-         log->info(Logr::Warning, "Done parsing NOTIFY-allowed zones from file", "file", Logging::Loggable(anff), "count", Logging::Loggable(newSet->size() - before)));
+         log->info(Logr::Notice, "Done parsing NOTIFY-allowed zones from file", "file", Logging::Loggable(anff), "count", Logging::Loggable(newSet->size() - before)));
   }
 
   return {newMap, newSet};
index fb88c8d675197ed4d0f2ef1b007bd71b6ac83591..d8350bdebebd6c517793750c3c9d2ec01241853c 100644 (file)
@@ -327,7 +327,7 @@ static bool dumpZoneToDisk(const shared_ptr<Logr::Logger>& plogger, const DNSNam
   int fd = mkstemp(&temp.at(0));
   if (fd < 0) {
     SLOG(g_log<<Logger::Warning<<"Unable to open a file to dump the content of the RPZ zone "<<zoneName<<endl,
-         logger->error(Logr::Warning, errno, "Unable to create temporary file"));
+         logger->error(Logr::Error, errno, "Unable to create temporary file"));
     return false;
   }
 
@@ -336,7 +336,7 @@ static bool dumpZoneToDisk(const shared_ptr<Logr::Logger>& plogger, const DNSNam
     int err = errno;
     close(fd);
     SLOG(g_log<<Logger::Warning<<"Unable to open a file pointer to dump the content of the RPZ zone "<<zoneName<<endl,
-         logger->error(Logr::Warning, err, "Unable to open file pointer"));
+         logger->error(Logr::Error, err, "Unable to open file pointer"));
     return false;
   }
 
@@ -345,7 +345,7 @@ static bool dumpZoneToDisk(const shared_ptr<Logr::Logger>& plogger, const DNSNam
   }
   catch(const std::exception& e) {
     SLOG(g_log<<Logger::Warning<<"Error while dumping the content of the RPZ zone "<<zoneName<<": "<<e.what()<<endl,
-         logger->error(Logr::Warning, e.what(), "Error while dumping the content of the RPZ"));
+         logger->error(Logr::Error, e.what(), "Error while dumping the content of the RPZ"));
     return false;
   }
 
@@ -357,19 +357,19 @@ static bool dumpZoneToDisk(const shared_ptr<Logr::Logger>& plogger, const DNSNam
 
   if (fsync(fileno(fp.get())) != 0) {
     SLOG(g_log<<Logger::Warning<<"Error while syncing the content of the RPZ zone "<<zoneName<<" to the dump file: "<<stringerror()<<endl,
-         logger->error(Logr::Warning, errno, "Error while syncing the content of the RPZ"));
+         logger->error(Logr::Error, errno, "Error while syncing the content of the RPZ"));
     return false;
   }
 
   if (fclose(fp.release()) != 0) {
     SLOG(g_log<<Logger::Warning<<"Error while writing the content of the RPZ zone "<<zoneName<<" to the dump file: "<<stringerror()<<endl,
-         logger->error(Logr::Warning, errno, "Error while writing the content of the RPZ"));
+         logger->error(Logr::Error, errno, "Error while writing the content of the RPZ"));
     return false;
   }
 
   if (rename(temp.c_str(), dumpZoneFileName.c_str()) != 0) {
     SLOG(g_log<<Logger::Warning<<"Error while moving the content of the RPZ zone "<<zoneName<<" to the dump file: "<<stringerror()<<endl,
-         logger->error(Logr::Warning, errno, "Error while moving the content of the RPZ", "destination_file", Logging::Loggable(dumpZoneFileName)));
+         logger->error(Logr::Error, errno, "Error while moving the content of the RPZ", "destination_file", Logging::Loggable(dumpZoneFileName)));
     return false;
   }