]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
auth: add loglevel-show setting. ixfrdist: prefixed logging is now structured logging.
authorPeter van Dijk <peter.van.dijk@powerdns.com>
Fri, 21 Jul 2023 10:49:28 +0000 (12:49 +0200)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Thu, 2 Nov 2023 15:05:51 +0000 (16:05 +0100)
fixes #12988

docs/settings.rst
pdns/auth-main.cc
pdns/logger.cc
pdns/logger.hh

index ef487677f2d40196c657561b2563e7d242d6bf68..411580207f22063266b185f454e3d3a450bdddde 100644 (file)
@@ -974,6 +974,18 @@ Corresponds to "syslog" level values (e.g. 0 = emergency, 1 = alert, 2 = critica
 Each level includes itself plus the lower levels before it.
 Not recommended to set this below 3.
 
+.. _setting-loglevel-show:
+
+``loglevel-show``
+-------------------
+
+-  Bool
+-  Default: no
+
+.. versionadded:: 4.9.0
+
+When enabled, log messages are formatted like structured logs, including their log level/priority: ``msg="Unable to launch, no backends configured for querying" prio="Error"``
+
 .. _setting-lua-axfr-script:
 
 ``lua-axfr-script``
index 559e1f29c358a6656b198e6a5b63bdbf0ce385f9..4e74f8e5b05deeede72647a1a865b91bd5a311d3 100644 (file)
@@ -193,6 +193,7 @@ static void declareArguments()
   ::arg().set("version-string", "PowerDNS version in packets - full, anonymous, powerdns or custom") = "full";
   ::arg().set("control-console", "Debugging switch - don't use") = "no"; // but I know you will!
   ::arg().set("loglevel", "Amount of logging. Higher is more. Do not set below 3") = "4";
+  ::arg().setSwitch("loglevel-show", "Include log level indicator in log output") = "no";
   ::arg().set("disable-syslog", "Disable logging to syslog, useful when running inside a supervisor that logs stdout") = "no";
   ::arg().set("log-timestamp", "Print timestamps in log lines") = "yes";
   ::arg().set("distributor-threads", "Default number of Distributor (backend) threads to start") = "3";
@@ -1272,6 +1273,7 @@ int main(int argc, char** argv)
     ::arg().set("slave-cycle-interval") = ::arg()["xfr-cycle-interval"];
 
     g_log.setLoglevel((Logger::Urgency)(::arg().asNum("loglevel")));
+    g_log.setPrefixed(::arg().mustDo("loglevel-show"));
     g_log.disableSyslog(::arg().mustDo("disable-syslog"));
     g_log.setTimestamps(::arg().mustDo("log-timestamp"));
     g_log.toConsole((Logger::Urgency)(::arg().asNum("loglevel")));
index ce0cbafa22c258957b817e24d251a0396dbef03b..a22ccb3fbc07940c9c1ebe5a8158d68d3969aa0d 100644 (file)
@@ -23,6 +23,7 @@
 #include "config.h"
 #endif
 
+#include <iomanip>
 #include <mutex>
 
 #include "logger.hh"
@@ -67,42 +68,47 @@ void Logger::log(const string& msg, Urgency u) noexcept
       }
     }
 
-    string prefix;
+    string severity;
     if (d_prefixed) {
       switch (u) {
       case All:
-        prefix = "[all] ";
+        severity = "All";
         break;
       case Alert:
-        prefix = "[ALERT] ";
+        severity = "Alert";
         break;
       case Critical:
-        prefix = "[CRITICAL] ";
+        severity = "Critical";
         break;
       case Error:
-        prefix = "[ERROR] ";
+        severity = "Error";
         break;
       case Warning:
-        prefix = "[WARNING] ";
+        severity = "Warning";
         break;
       case Notice:
-        prefix = "[NOTICE] ";
+        severity = "Notice";
         break;
       case Info:
-        prefix = "[INFO] ";
+        severity = "Info";
         break;
       case Debug:
-        prefix = "[DEBUG] ";
+        severity = "Debug";
         break;
       case None:
-        prefix = "[none] ";
+        severity = "None";
         break;
       }
     }
 
     static std::mutex m;
     std::lock_guard<std::mutex> l(m); // the C++-2011 spec says we need this, and OSX actually does
-    clog << string(buffer) + prefix + msg << endl;
+    if (d_prefixed) {
+      clog << string(static_cast<char*>(&buffer[0])) << "msg=" << std::quoted(msg) << " prio=" << std::quoted(severity) << endl;
+    }
+    else {
+      clog << string(static_cast<char*>(&buffer[0])) << msg << endl;
+    }
 #ifndef RECURSOR
     mustAccount = true;
 #endif
index dbe7f278b2da5db1bdac9f4deb290b804e7fcf6c..2b01700382aa80b10d742090dc171422e27c656d 100644 (file)
@@ -156,7 +156,7 @@ private:
   bool opened;
   bool d_disableSyslog;
   bool d_timestamps{true};
-  bool d_prefixed{false};
+  bool d_prefixed{false}; // this used to prefix the loglevel, but now causes formatting like structured logging
 };
 
 Logger& getLogger();