From: Pieter Lexis Date: Thu, 12 Apr 2018 15:06:42 +0000 (+0200) Subject: logger: Allow logging with the severity prefix X-Git-Tag: dnsdist-1.3.1~148^2~5 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e908ad8700e6e6a497ae06ca5f9a46efce725251;p=pdns logger: Allow logging with the severity prefix --- diff --git a/pdns/logger.cc b/pdns/logger.cc index 8bbf03307..1766d35ae 100644 --- a/pdns/logger.cc +++ b/pdns/logger.cc @@ -51,9 +51,42 @@ void Logger::log(const string &msg, Urgency u) strftime(buffer,sizeof(buffer),"%b %d %H:%M:%S ", &tm); } + string prefix; + if (d_prefixed) { + switch(u) { + case All: + prefix = "[all] "; + break; + case Alert: + prefix = "[ALERT] "; + break; + case Critical: + prefix = "[CRITICAL] "; + break; + case Error: + prefix = "[ERROR] "; + break; + case Warning: + prefix = "[WARNING] "; + break; + case Notice: + prefix = "[NOTICE] "; + break; + case Info: + prefix = "[INFO] "; + break; + case Debug: + prefix = "[DEBUG] "; + break; + case None: + prefix = "[none] "; + break; + } + } + static pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER; Lock l(&m); // the C++-2011 spec says we need this, and OSX actually does - clog << string(buffer) + msg <