Skip to content

Commit

Permalink
- Log all things as key-value pairs, inclusing err and msg
Browse files Browse the repository at this point in the history
- Use existing logger as backend, quote values
- Fix a const issue
- Level <-> Urgency mapping has to be done better
  • Loading branch information
omoerbeek committed Apr 28, 2021
1 parent b3c8edd commit 0acc65a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 21 deletions.
39 changes: 23 additions & 16 deletions pdns/pdns_recursor.cc
Expand Up @@ -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;
Expand Down Expand Up @@ -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())) {
Expand Down
6 changes: 3 additions & 3 deletions pdns/recursordist/logging.cc
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
}

Expand Down
4 changes: 2 additions & 2 deletions pdns/recursordist/logging.hh
Expand Up @@ -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;
Expand Down

0 comments on commit 0acc65a

Please sign in to comment.