]> git.ipfire.org Git - thirdparty/pdns.git/blobdiff - pdns/dolog.hh
dnsdist: add --log-timestamps flag
[thirdparty/pdns.git] / pdns / dolog.hh
index 557c767aadeecb1933c978324e974c854efb469f..fd6097dd105dbb8793845b0464ba48a4a91512a4 100644 (file)
@@ -22,6 +22,7 @@
 #pragma once
 #include <iostream>
 #include <sstream>
+#include "config.h"
 #if !defined(RECURSOR)
 #include <syslog.h>
 #else
@@ -75,6 +76,9 @@ void dolog(std::ostream& os, const char* s, T value, Args... args)
 
 extern bool g_verbose;
 extern bool g_syslog;
+#ifdef DNSDIST
+extern bool g_logtimestamps;
+#endif
 
 inline void setSyslogFacility(int facility)
 {
@@ -88,8 +92,22 @@ void genlog(int level, const char* s, Args... args)
 {
   std::ostringstream str;
   dolog(str, s, args...);
+
   if(g_syslog)
     syslog(level, "%s", str.str().c_str());
+
+#ifdef DNSDIST
+  if (g_logtimestamps) {
+    char buffer[50] = "";
+    struct tm tm;
+    time_t t;
+    time(&t);
+    localtime_r(&t, &tm);
+    strftime(buffer, sizeof(buffer), "%b %d %H:%M:%S ", &tm);
+    std::cout<<buffer;
+  }
+#endif
+
   std::cout<<str.str()<<std::endl;
 }