From: Peter van Dijk Date: Fri, 21 Jul 2023 10:49:28 +0000 (+0200) Subject: auth: add loglevel-show setting. ixfrdist: prefixed logging is now structured logging. X-Git-Tag: rec-5.0.0-rc1~12^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=46eec001e8bcf7e0af49b8e28832af2f2d2474ba;p=thirdparty%2Fpdns.git auth: add loglevel-show setting. ixfrdist: prefixed logging is now structured logging. fixes #12988 --- diff --git a/docs/settings.rst b/docs/settings.rst index ef487677f2..411580207f 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -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`` diff --git a/pdns/auth-main.cc b/pdns/auth-main.cc index 559e1f29c3..4e74f8e5b0 100644 --- a/pdns/auth-main.cc +++ b/pdns/auth-main.cc @@ -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"))); diff --git a/pdns/logger.cc b/pdns/logger.cc index ce0cbafa22..a22ccb3fbc 100644 --- a/pdns/logger.cc +++ b/pdns/logger.cc @@ -23,6 +23,7 @@ #include "config.h" #endif +#include #include #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 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(&buffer[0])) << "msg=" << std::quoted(msg) << " prio=" << std::quoted(severity) << endl; + } + else { + clog << string(static_cast(&buffer[0])) << msg << endl; + } #ifndef RECURSOR mustAccount = true; #endif diff --git a/pdns/logger.hh b/pdns/logger.hh index dbe7f278b2..2b01700382 100644 --- a/pdns/logger.hh +++ b/pdns/logger.hh @@ -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();