]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
- Log all things as key-value pairs, inclusing err and msg
authorOtto <otto.moerbeek@open-xchange.com>
Wed, 28 Apr 2021 12:48:22 +0000 (14:48 +0200)
committerOtto <otto.moerbeek@open-xchange.com>
Wed, 28 Apr 2021 12:50:18 +0000 (14:50 +0200)
- Use existing logger as backend, quote values
- Fix a const issue
- Level <-> Urgency mapping has to be done better

pdns/pdns_recursor.cc
pdns/recursordist/logging.cc
pdns/recursordist/logging.hh

index b1fda8118fadcdd479d9b45cbc79003bba89fb97..87ec61824521c53b99346127f9abf60d90b856ea 100644 (file)
@@ -5393,6 +5393,28 @@ catch(...) {
 }
 
 
+
+static void loggerBackend(std::unique_ptr<Logging::Entry> entry) {
+  static thread_local std::stringstream buf;
+
+  buf.str("");
+  buf << "msg=" << std::quoted(entry->message);
+  if (entry->error) {
+    buf << " oserror=" << std::quoted(entry->error.get());
+  }
+
+  if (entry->name) {
+    buf << " subsystem=" << std::quoted(entry->name.get());
+  }
+
+  for (auto const& v: entry->values) {
+    buf << " ";
+    buf << v.first << "=" << std::quoted(v.second);
+  }
+  g_log << Logger::Urgency(entry->level) << buf.str() << endl;
+}
+
+
 int main(int argc, char **argv)
 {
   g_argc = argc;
@@ -5675,22 +5697,7 @@ int main(int argc, char **argv)
       exit(0);
     }
 
-    g_slog = Logging::Logger::create([](std::unique_ptr<Logging::Entry> entry) {
-      if (entry->error) {
-        std::cout << "ERR ";
-      } else {
-        std::cout << "INFO";
-     }
-      if (entry->name) {
-        std::cout << entry->name.get() << ": ";
-      }
-      std::cout << entry->message;
-      for (auto const& v: entry->values) {
-        std::cout << " ";
-        std::cout << v.first << "=" << v.second;
-      }
-      std::cout << std::endl;
-    });
+    g_slog = Logging::Logger::create(loggerBackend);
     auto startupLog = g_slog->withName("startup");
 
     if(!::arg().file(configname.c_str())) {
index 2b172d917e012c1953e0ee8c78dcef244f4b63d6..7a81bd5818be8e88a4a01a34575c7fb69c7c00a1 100644 (file)
@@ -79,7 +79,7 @@ namespace Logging
 
   std::shared_ptr<Logr::Logger> Logger::withValues(const std::string& key, const Logr::Loggable& value)
   {
-    auto res = std::make_shared<Logger>(getptr(), _name.get(), _level, _callback);
+    auto res = std::make_shared<Logger>(getptr(), _name, _level, _callback);
     res->_values.insert({key, value.to_string()});
     res->setVerbosity(getVerbosity());
     return res;
@@ -135,10 +135,10 @@ namespace Logging
   Logger::Logger(EntryLogger callback) : _callback(callback)
   {
   }
-  Logger::Logger(EntryLogger callback, boost::optional<const std::string> name) : _callback(callback), _name(name)
+  Logger::Logger(EntryLogger callback, boost::optional<std::string> name) : _callback(callback), _name(name)
   {
   }
-  Logger::Logger(std::shared_ptr<Logger> parent, boost::optional<const std::string> name, size_t lvl,  EntryLogger callback) : _parent(parent), _callback(callback), _name(name), _level(lvl)
+  Logger::Logger(std::shared_ptr<Logger> parent, boost::optional<std::string> name, size_t lvl,  EntryLogger callback) : _parent(parent), _callback(callback), _name(name), _level(lvl)
   {
   }
 
index 246611023bdadbf0de25bf12b553041a7dfadbb3..71c7aa781dcdecfa1a062e9842c05579225b9392 100644 (file)
@@ -82,8 +82,8 @@ namespace Logging {
     static std::shared_ptr<Logger> create(EntryLogger callback, const std::string& name);
 
     Logger(EntryLogger callback);
-    Logger(EntryLogger callback, boost::optional<const std::string> name);
-    Logger(std::shared_ptr<Logger> parent, boost::optional<const std::string> name, size_t lvl,  EntryLogger callback);
+    Logger(EntryLogger callback, boost::optional<std::string> name);
+    Logger(std::shared_ptr<Logger> parent, boost::optional<std::string> name, size_t lvl,  EntryLogger callback);
     virtual ~Logger();
 
     size_t getVerbosity() const;