]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
chore(rec): update the logger to use std::optional
authorPieter Lexis <pieter.lexis@powerdns.com>
Thu, 13 Nov 2025 15:45:22 +0000 (16:45 +0100)
committerPieter Lexis <pieter.lexis@powerdns.com>
Fri, 28 Nov 2025 12:39:35 +0000 (13:39 +0100)
pdns/logging.hh
pdns/recursordist/logging.cc
pdns/recursordist/rec-main.cc
pdns/recursordist/rec_control.cc
pdns/recursordist/testrunner.cc

index a927ea9daeb9c13b29c600b0153a81f61c338b11..548859503037b39517965ba2c55a3da8f95f5a8f 100644 (file)
@@ -41,9 +41,9 @@ namespace Logging
 
 struct Entry
 {
-  boost::optional<std::string> name; // name parts joined with '.'
+  std::optional<std::string> name; // name parts joined with '.'
   std::string message; // message as send to log call
-  boost::optional<std::string> error; // error if .Error() was called
+  std::optional<std::string> error; // error if .Error() was called
   struct timeval d_timestamp; // time of entry generation
   std::map<std::string, std::string> values; // key-value pairs
   size_t level; // level at which this was logged
@@ -183,21 +183,21 @@ public:
   static std::shared_ptr<Logger> create(EntryLogger callback, const std::string& name);
 
   Logger(EntryLogger callback);
-  Logger(EntryLogger callback, boost::optional<std::string> name);
-  Logger(std::shared_ptr<const Logger> parent, boost::optional<std::string> name, size_t verbosity, size_t lvl, EntryLogger callback);
+  Logger(EntryLogger callback, std::optional<std::string> name);
+  Logger(std::shared_ptr<const Logger> parent, std::optional<std::string> 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<const std::string> err) const;
-  void logMessage(const std::string& msg, Logr::Priority p, boost::optional<const std::string> err) const;
+  void logMessage(const std::string& msg, const std::optional<std::string>& err) const;
+  void logMessage(const std::string& msg, Logr::Priority prio, const std::optional<std::string>& err) const;
   std::shared_ptr<const Logger> getptr() const;
 
   std::shared_ptr<const Logger> _parent{nullptr};
   EntryLogger _callback;
-  boost::optional<std::string> _name;
+  std::optional<std::string> _name;
   std::map<std::string, std::string> _values;
   // current Logger's level. the higher the more verbose.
   size_t _level{0};
index b6aaef6624f2573cc11831cffa5f36a1423aa6b0..b72aa308f64f6b8634ac901e88b8e3f99dc8a389 100644 (file)
@@ -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<const std::string> err) const
+void Logger::logMessage(const std::string& msg, const std::optional<std::string>& err) const
 {
   logMessage(msg, Logr::Absent, std::move(err));
 }
 
-void Logger::logMessage(const std::string& msg, Logr::Priority prio, boost::optional<const std::string> err) const
+void Logger::logMessage(const std::string& msg, Logr::Priority prio, const std::optional<std::string>& err) const
 {
   if (!enabled(prio)) {
     return;
@@ -111,7 +111,7 @@ std::shared_ptr<Logr::Logger> Logger::withName(const std::string& name) const
 {
   std::shared_ptr<Logger> res;
   if (_name) {
-    res = std::make_shared<Logger>(getptr(), _name.get() + "." + name, getVerbosity(), _level, _callback);
+    res = std::make_shared<Logger>(getptr(), _name.value() + "." + name, getVerbosity(), _level, _callback);
   }
   else {
     res = std::make_shared<Logger>(getptr(), name, getVerbosity(), _level, _callback);
@@ -142,11 +142,11 @@ Logger::Logger(EntryLogger callback) :
   _callback(callback)
 {
 }
-Logger::Logger(EntryLogger callback, boost::optional<std::string> name) :
+Logger::Logger(EntryLogger callback, std::optional<std::string> name) :
   _callback(callback), _name(std::move(name))
 {
 }
-Logger::Logger(std::shared_ptr<const Logger> parent, boost::optional<std::string> name, size_t verbosity, size_t lvl, EntryLogger callback) :
+Logger::Logger(std::shared_ptr<const Logger> parent, std::optional<std::string> name, size_t verbosity, size_t lvl, EntryLogger callback) :
   _parent(std::move(parent)), _callback(callback), _name(std::move(name)), _level(lvl), _verbosity(verbosity)
 {
 }
index 1ce5249913c1c6e9cd55885b2417ceaefafdc1e6..ca0cd185fbd00d2a018351b835a4e13ef9b2f15b 100644 (file)
@@ -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<char, 64> 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) {
index 8a5ff53e2719c9425f48b862f7f325b9ff66fe66..d2dc7d55f50c618a4bd75f347735d0c7d06758a9 100644 (file)
@@ -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) {
index c07ca65c6e5750fb579b12168a0bdb4c808a1d3d..d62c4e9fa411f305e98f9c5aa0d64d24f02f9b85 100644 (file)
@@ -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) {