diff --git a/pdns/pdns_recursor.cc b/pdns/pdns_recursor.cc index b1fda8118fad..87ec61824521 100644 --- a/pdns/pdns_recursor.cc +++ b/pdns/pdns_recursor.cc @@ -5393,6 +5393,28 @@ catch(...) { } + +static void loggerBackend(std::unique_ptr 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 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())) { diff --git a/pdns/recursordist/logging.cc b/pdns/recursordist/logging.cc index 2b172d917e01..7a81bd5818be 100644 --- a/pdns/recursordist/logging.cc +++ b/pdns/recursordist/logging.cc @@ -79,7 +79,7 @@ namespace Logging std::shared_ptr Logger::withValues(const std::string& key, const Logr::Loggable& value) { - auto res = std::make_shared(getptr(), _name.get(), _level, _callback); + auto res = std::make_shared(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 name) : _callback(callback), _name(name) + Logger::Logger(EntryLogger callback, boost::optional name) : _callback(callback), _name(name) { } - Logger::Logger(std::shared_ptr parent, boost::optional name, size_t lvl, EntryLogger callback) : _parent(parent), _callback(callback), _name(name), _level(lvl) + Logger::Logger(std::shared_ptr parent, boost::optional name, size_t lvl, EntryLogger callback) : _parent(parent), _callback(callback), _name(name), _level(lvl) { } diff --git a/pdns/recursordist/logging.hh b/pdns/recursordist/logging.hh index 246611023bda..71c7aa781dcd 100644 --- a/pdns/recursordist/logging.hh +++ b/pdns/recursordist/logging.hh @@ -82,8 +82,8 @@ namespace Logging { 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 lvl, EntryLogger callback); + Logger(EntryLogger callback, boost::optional name); + Logger(std::shared_ptr parent, boost::optional name, size_t lvl, EntryLogger callback); virtual ~Logger(); size_t getVerbosity() const;