From: Pieter Lexis Date: Thu, 13 Nov 2025 15:45:22 +0000 (+0100) Subject: chore(rec): update the logger to use std::optional X-Git-Tag: rec-5.4.0-alpha1~33^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=400444264077949f31c2e723f6aaafce3ee929ee;p=thirdparty%2Fpdns.git chore(rec): update the logger to use std::optional --- diff --git a/pdns/logging.hh b/pdns/logging.hh index a927ea9dae..5488595030 100644 --- a/pdns/logging.hh +++ b/pdns/logging.hh @@ -41,9 +41,9 @@ namespace Logging struct Entry { - boost::optional name; // name parts joined with '.' + std::optional name; // name parts joined with '.' std::string message; // message as send to log call - boost::optional error; // error if .Error() was called + std::optional error; // error if .Error() was called struct timeval d_timestamp; // time of entry generation std::map values; // key-value pairs size_t level; // level at which this was logged @@ -183,21 +183,21 @@ public: static std::shared_ptr create(EntryLogger callback, const std::string& name); Logger(EntryLogger callback); - Logger(EntryLogger callback, boost::optional name); - Logger(std::shared_ptr parent, boost::optional name, size_t verbosity, size_t lvl, EntryLogger callback); + Logger(EntryLogger callback, std::optional name); + Logger(std::shared_ptr parent, std::optional name, size_t verbosity, size_t lvl, EntryLogger callback); ~Logger() override; size_t getVerbosity() const; void setVerbosity(size_t verbosity); private: - void logMessage(const std::string& msg, boost::optional err) const; - void logMessage(const std::string& msg, Logr::Priority p, boost::optional err) const; + void logMessage(const std::string& msg, const std::optional& err) const; + void logMessage(const std::string& msg, Logr::Priority prio, const std::optional& err) const; std::shared_ptr getptr() const; std::shared_ptr _parent{nullptr}; EntryLogger _callback; - boost::optional _name; + std::optional _name; std::map _values; // current Logger's level. the higher the more verbose. size_t _level{0}; diff --git a/pdns/recursordist/logging.cc b/pdns/recursordist/logging.cc index b6aaef6624..b72aa308f6 100644 --- a/pdns/recursordist/logging.cc +++ b/pdns/recursordist/logging.cc @@ -40,20 +40,20 @@ bool Logger::enabled(Logr::Priority prio) const void Logger::info(const std::string& msg) const { - logMessage(msg, Logr::Absent, boost::none); + logMessage(msg, Logr::Absent, std::nullopt); } void Logger::info(Logr::Priority prio, const std::string& msg) const { - logMessage(msg, prio, boost::none); + logMessage(msg, prio, std::nullopt); } -void Logger::logMessage(const std::string& msg, boost::optional err) const +void Logger::logMessage(const std::string& msg, const std::optional& err) const { logMessage(msg, Logr::Absent, std::move(err)); } -void Logger::logMessage(const std::string& msg, Logr::Priority prio, boost::optional err) const +void Logger::logMessage(const std::string& msg, Logr::Priority prio, const std::optional& err) const { if (!enabled(prio)) { return; @@ -111,7 +111,7 @@ std::shared_ptr Logger::withName(const std::string& name) const { std::shared_ptr res; if (_name) { - res = std::make_shared(getptr(), _name.get() + "." + name, getVerbosity(), _level, _callback); + res = std::make_shared(getptr(), _name.value() + "." + name, getVerbosity(), _level, _callback); } else { res = std::make_shared(getptr(), name, getVerbosity(), _level, _callback); @@ -142,11 +142,11 @@ Logger::Logger(EntryLogger callback) : _callback(callback) { } -Logger::Logger(EntryLogger callback, boost::optional name) : +Logger::Logger(EntryLogger callback, std::optional name) : _callback(callback), _name(std::move(name)) { } -Logger::Logger(std::shared_ptr parent, boost::optional name, size_t verbosity, size_t lvl, EntryLogger callback) : +Logger::Logger(std::shared_ptr parent, std::optional name, size_t verbosity, size_t lvl, EntryLogger callback) : _parent(std::move(parent)), _callback(callback), _name(std::move(name)), _level(lvl), _verbosity(verbosity) { } diff --git a/pdns/recursordist/rec-main.cc b/pdns/recursordist/rec-main.cc index 1ce5249913..ca0cd185fb 100644 --- a/pdns/recursordist/rec-main.cc +++ b/pdns/recursordist/rec-main.cc @@ -1070,12 +1070,12 @@ static void loggerSDBackend(const Logging::Entry& entry) }; appendKeyAndVal("MESSAGE", entry.message); if (entry.error) { - appendKeyAndVal("ERROR", entry.error.get()); + appendKeyAndVal("ERROR", entry.error.value()); } appendKeyAndVal("LEVEL", std::to_string(entry.level)); appendKeyAndVal("PRIORITY", std::to_string(entry.d_priority)); if (entry.name) { - appendKeyAndVal("SUBSYSTEM", entry.name.get()); + appendKeyAndVal("SUBSYSTEM", entry.name.value()); } std::array timebuf{}; appendKeyAndVal("TIMESTAMP", Logging::toTimestampStringMilli(entry.d_timestamp, timebuf)); @@ -1124,11 +1124,11 @@ static void loggerJSONBackend(const Logging::Entry& entry) }; if (entry.error) { - json.emplace("error", entry.error.get()); + json.emplace("error", entry.error.value()); } if (entry.name) { - json.emplace("subsystem", entry.name.get()); + json.emplace("subsystem", entry.name.value()); } if (entry.d_priority != 0) { @@ -1160,11 +1160,11 @@ static void loggerBackend(const Logging::Entry& entry) buf.str(""); buf << "msg=" << std::quoted(entry.message); if (entry.error) { - buf << " error=" << std::quoted(entry.error.get()); + buf << " error=" << std::quoted(entry.error.value()); } if (entry.name) { - buf << " subsystem=" << std::quoted(entry.name.get()); + buf << " subsystem=" << std::quoted(entry.name.value()); } buf << " level=" << std::quoted(std::to_string(entry.level)); if (entry.d_priority != 0) { diff --git a/pdns/recursordist/rec_control.cc b/pdns/recursordist/rec_control.cc index 8a5ff53e27..d2dc7d55f5 100644 --- a/pdns/recursordist/rec_control.cc +++ b/pdns/recursordist/rec_control.cc @@ -299,11 +299,11 @@ static void recControlLoggerBackend(const Logging::Entry& entry) buf.str(""); buf << "msg=" << std::quoted(entry.message); if (entry.error) { - buf << " error=" << std::quoted(entry.error.get()); + buf << " error=" << std::quoted(entry.error.value()); } if (entry.name) { - buf << " subsystem=" << std::quoted(entry.name.get()); + buf << " subsystem=" << std::quoted(entry.name.value()); } buf << " level=" << std::quoted(std::to_string(entry.level)); if (entry.d_priority != 0) { diff --git a/pdns/recursordist/testrunner.cc b/pdns/recursordist/testrunner.cc index c07ca65c6e..d62c4e9fa4 100644 --- a/pdns/recursordist/testrunner.cc +++ b/pdns/recursordist/testrunner.cc @@ -46,11 +46,11 @@ 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 << " oserror=" << std::quoted(entry.error.value()); } if (entry.name) { - buf << " subsystem=" << std::quoted(entry.name.get()); + buf << " subsystem=" << std::quoted(entry.name.value()); } buf << " level=" << entry.level; if (entry.d_priority != 0) {