From: Otto Moerbeek Date: Fri, 1 Mar 2024 10:54:35 +0000 (+0100) Subject: rec: remove the possiblility to disable structured logging X-Git-Tag: rec-5.1.0-alpha1~87^2~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2b23ecf2a4539a48d4e108a902db76a6608de00f;p=thirdparty%2Fpdns.git rec: remove the possiblility to disable structured logging --- diff --git a/pdns/logging.hh b/pdns/logging.hh index c08a8e6b4e..edde72d4b3 100644 --- a/pdns/logging.hh +++ b/pdns/logging.hh @@ -206,8 +206,10 @@ private: extern std::shared_ptr g_slog; -// Prefer structured logging? -extern bool g_slogStructured; +// Prefer structured logging? Since 5.1.0, we always do. We keep a const, to allow for step-by-step +// removal of old style logging code (for recursor-only code). Note that code shared with auth still uses +// old-style, so the SLOG calls should remain for shared code. +constexpr bool g_slogStructured = true; // A helper macro to switch between old-style logging and new-style (structured logging) // A typical use: diff --git a/pdns/recursordist/docs/upgrade.rst b/pdns/recursordist/docs/upgrade.rst index e0bdce14d2..39b42c9f7f 100644 --- a/pdns/recursordist/docs/upgrade.rst +++ b/pdns/recursordist/docs/upgrade.rst @@ -10,7 +10,12 @@ When upgrading several versions, please read **all** notes applying to the upgra Changed settings ---------------- -For YAML settings only: the type of the :ref:`setting-yaml-incoming.edns_padding_from` and :ref:`setting-yaml-incoming.proxy_protocol_from` has been changed from ``String`` to ``Sequence of Subnet``. +- For YAML settings only: the type of the :ref:`setting-yaml-incoming.edns_padding_from` and :ref:`setting-yaml-incoming.proxy_protocol_from` has been changed from ``String`` to ``Sequence of Subnet``. + +- Disabling :ref:`setting-structured-logging` is no longer supported. + +Changed Settings +^^^^^^^^^^^^^^^^ 5.0.2 to 5.0.3, 4.9.3 to 4.9.4 and 4.8.6 to 4.8.7 ------------------------------------------------- diff --git a/pdns/recursordist/logging.cc b/pdns/recursordist/logging.cc index 42c1d2a20d..84d0c2b134 100644 --- a/pdns/recursordist/logging.cc +++ b/pdns/recursordist/logging.cc @@ -156,4 +156,3 @@ Logger::~Logger() }; std::shared_ptr g_slog{nullptr}; -bool g_slogStructured = true; diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index 69b59cec92..bd8658515e 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -3082,7 +3082,6 @@ int main(int argc, char** argv) // Pick up options given on command line to setup logging asap. g_quiet = ::arg().mustDo("quiet"); s_logUrgency = (Logger::Urgency)::arg().asNum("loglevel"); - g_slogStructured = ::arg().mustDo("structured-logging"); s_structured_logger_backend = ::arg()["structured-logging-backend"]; if (!g_quiet && s_logUrgency < Logger::Info) { // Logger::Info=6, Logger::Debug=7 @@ -3091,8 +3090,8 @@ int main(int argc, char** argv) g_log.setLoglevel(s_logUrgency); g_log.toConsole(s_logUrgency); showProductVersion(); - if (!g_slogStructured) { - g_log << Logger::Warning << "Disabling structured logging is deprecated, old-style logging wil be removed in a future release" << endl; + if (!::arg().mustDo("structured-logging")) { + g_log << Logger::Error << "Disabling structured logging is not supported anymore" << endl; } g_yamlSettings = false; @@ -3182,7 +3181,6 @@ int main(int argc, char** argv) g_quiet = ::arg().mustDo("quiet"); s_logUrgency = (Logger::Urgency)::arg().asNum("loglevel"); - g_slogStructured = ::arg().mustDo("structured-logging"); if (s_logUrgency < Logger::Error) { s_logUrgency = Logger::Error; diff --git a/pdns/recursordist/rec_control.cc b/pdns/recursordist/rec_control.cc index 4ac9de949a..98383671d2 100644 --- a/pdns/recursordist/rec_control.cc +++ b/pdns/recursordist/rec_control.cc @@ -24,6 +24,7 @@ #endif #include +#include #include #include "pdnsexception.hh" @@ -32,6 +33,8 @@ #include "namespaces.hh" #include "rec_channel.hh" #include "settings/cxxsettings.hh" +#include "logger.hh" +#include "logging.hh" ArgvMap& arg() { @@ -39,7 +42,7 @@ ArgvMap& arg() return arg; } -static void initArguments(int argc, char** argv) +static void initArguments(int argc, char** argv, Logr::log_t log) { arg().set("config-dir", "Location of configuration directory (recursor.conf)") = SYSCONFDIR; @@ -81,11 +84,11 @@ static void initArguments(int argc, char** argv) case pdns::settings::rec::YamlSettingsStatus::CannotOpen: break; case pdns::settings::rec::YamlSettingsStatus::PresentButFailed: - cerr << "YAML config found for configname '" << yamlconfigname << "' but error ocurred processing it" << endl; + log->error(Logr::Error, msg, "YAML config found, but error ocurred processing it", "configname", Logging::Loggable(yamlconfigname)); exit(1); // NOLINT(concurrency-mt-unsafe) break; case pdns::settings::rec::YamlSettingsStatus::OK: - cout << "YAML config found and processed for configname '" << yamlconfigname << "'" << endl; + log->info(Logr::Notice, "YAML config found and processed", "configname", Logging::Loggable(yamlconfigname)); pdns::settings::rec::bridgeStructToOldStyleSettings(settings); break; } @@ -235,9 +238,51 @@ static RecursorControlChannel::Answer showYAML(const std::string& path) } } +static void recControlLoggerBackend(const Logging::Entry& entry) +{ + static thread_local std::stringstream buf; + + // First map SL priority to syslog's Urgency + Logger::Urgency urg = entry.d_priority != 0 ? Logger::Urgency(entry.d_priority) : Logger::Info; + if (urg > Logger::Warning) { + // We do not log anything if the Urgency of the message is lower than the requested loglevel. + // Not that lower Urgency means higher number. + return; + } + buf.str(""); + buf << "msg=" << std::quoted(entry.message); + if (entry.error) { + buf << " error=" << std::quoted(entry.error.get()); + } + + if (entry.name) { + buf << " subsystem=" << std::quoted(entry.name.get()); + } + buf << " level=" << std::quoted(std::to_string(entry.level)); + if (entry.d_priority != 0) { + buf << " prio=" << std::quoted(Logr::Logger::toString(entry.d_priority)); + } +#if 0 + // Thread id filled in by backend, since the SL code does not know about RecursorThreads + // We use the Recursor thread, other threads get id 0. May need to revisit. + buf << " tid=" << std::quoted(std::to_string(RecThreadInfo::id())); + std::array timebuf{}; + buf << " ts=" << std::quoted(toTimestampStringMilli(entry.d_timestamp, timebuf)); +#endif + for (auto const& value : entry.values) { + buf << " "; + buf << value.first << "=" << std::quoted(value.second); + } + + cerr << buf.str() << endl; +} + int main(int argc, char** argv) { - g_slogStructured = false; + g_slog = Logging::Logger::create(recControlLoggerBackend); + auto log = g_slog->withName("config"); + ::arg().setSLog(log); + const set fileCommands = { "dump-cache", "dump-edns", @@ -252,7 +297,7 @@ int main(int argc, char** argv) "trace-regex", }; try { - initArguments(argc, argv); + initArguments(argc, argv, log); string sockname = "pdns_recursor"; if (arg()["config-name"] != "") @@ -355,7 +400,7 @@ int main(int argc, char** argv) return receive.d_ret; } catch (PDNSException& ae) { - cerr << "Fatal: " << ae.reason << "\n"; + log->error(Logr::Error, ae.reason, "Fatal"); return 1; } } diff --git a/pdns/recursordist/settings/table.py b/pdns/recursordist/settings/table.py index 0d9da85d45..78b87ac4eb 100644 --- a/pdns/recursordist/settings/table.py +++ b/pdns/recursordist/settings/table.py @@ -2657,6 +2657,7 @@ Prefer structured logging when both an old style and a structured log messages i ''', 'versionadded': '4.6.0', 'versionchanged': ('5.0.0', 'Disabling structured logging is deprecated'), + 'versionchanged': ('5.1.0', 'Disabling structured logging is not supported'), }, { 'name' : 'structured_logging_backend', diff --git a/regression-tests.recursor/YAMLConversion/expected_result b/regression-tests.recursor/YAMLConversion/expected_result index 601b9a21de..b045201638 100644 --- a/regression-tests.recursor/YAMLConversion/expected_result +++ b/regression-tests.recursor/YAMLConversion/expected_result @@ -1,2 +1 @@ -YAML config found and processed for configname './recursor.yml' bye nicely