]> granicus.if.org Git - pdns/commitdiff
Add log-timestamp option
authorPieter Lexis <pieter.lexis@powerdns.com>
Wed, 25 Oct 2017 09:17:58 +0000 (11:17 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Wed, 25 Oct 2017 09:57:04 +0000 (11:57 +0200)
This option can be used to disable printing timestamps to stdout, this
is useful when using systemd-journald or another supervisor that
timestamps stdout by itself. As the logs will not have 2 timestamps.

docs/settings.rst
pdns/common_startup.cc
pdns/logger.cc
pdns/logger.hh
pdns/pdns.service.in
pdns/pdns_recursor.cc
pdns/receiver.cc
pdns/recursordist/docs/settings.rst
pdns/recursordist/pdns-recursor.service.in

index f67f185c2df994ee055400970e4e0e16ee0f660a..10e36f5518fb9409e28633312ebbe63e6d621d85 100644 (file)
@@ -673,6 +673,22 @@ big problems if you have multiple IP addresses. Unix does not provide a
 way of figuring out what IP address a packet was sent to when binding to
 any.
 
+.. _setting-log-timestamp:
+
+``log-timestamp``
+-----------------
+
+.. versionadded:: 4.1.0
+
+- Bool
+- Default: yes
+
+When printing log lines to stdout, prefix them with timestamps.
+Disable this if the process supervisor timestamps these lines already.
+
+.. note::
+  The systemd unit file supplied with the source code already disables timestamp printing
+
 .. _setting-non-local-bind:
 
 ``non-local-bind``
index 3bdc364f8449ad31e0506416b07f0640103e8367..1070ce001282974d2d901218b1e690aa709a07fa 100644 (file)
@@ -95,6 +95,7 @@ void declareArguments()
   ::arg().set("control-console","Debugging switch - don't use")="no"; // but I know you will!
   ::arg().set("loglevel","Amount of logging. Higher is more. Do not set below 3")="4";
   ::arg().set("disable-syslog","Disable logging to syslog, useful when running inside a supervisor that logs stdout")="no";
+  ::arg().set("log-timestamp","Print timestamps in log lines")="yes";
   ::arg().set("default-soa-name","name to insert in the SOA record if none set in the backend")="a.misconfigured.powerdns.server";
   ::arg().set("default-soa-mail","mail address to insert in the SOA record if none set in the backend")="";
   ::arg().set("distributor-threads","Default number of Distributor (backend) threads to start")="3";
index a720b88b4594aa03ac866b164ca6fe65960a3ef1..01eb6e4045abd5826a99bb1fe54a273c879225dd 100644 (file)
@@ -47,14 +47,16 @@ void Logger::log(const string &msg, Urgency u)
 #ifndef RECURSOR
   bool mustAccount(false);
 #endif
-  struct tm tm;
-  time_t t;
-  time(&t);
-  tm=*localtime(&t);
-
   if(u<=consoleUrgency) {
-    char buffer[50];
-    strftime(buffer,sizeof(buffer),"%b %d %H:%M:%S ", &tm);
+    char buffer[50] = "";
+    if (d_timestamps) {
+      struct tm tm;
+      time_t t;
+      time(&t);
+      tm=*localtime(&t);
+      strftime(buffer,sizeof(buffer),"%b %d %H:%M:%S ", &tm);
+    }
+
     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 <<endl;
index 6f1fb61338bcf0771b156c2e4d19fba22a25d5a1..989c921fcfcbbe138bc8959c64d5b1fc4b581c52 100644 (file)
@@ -60,6 +60,10 @@ public:
     d_disableSyslog = d;
   }
 
+  void setTimestamps(bool t) {
+    d_timestamps = t;
+  }
+
   //! Log to a file.
   void toFile( const string & filename );
   
@@ -107,6 +111,7 @@ private:
   Urgency consoleUrgency;
   bool opened;
   bool d_disableSyslog;
+  bool d_timestamps{true};
   static pthread_once_t s_once;
   static pthread_key_t s_loggerKey;
 };
index 6737196a7402ff62591c1efa61955f02b03ac712..e9bad4f01e0b2bfcd84f00c93134f53f2e457f84 100644 (file)
@@ -7,7 +7,7 @@ After=network-online.target mysqld.service postgresql.service slapd.service mari
 
 [Service]
 Type=notify
-ExecStart=@sbindir@/pdns_server --guardian=no --daemon=no --disable-syslog --write-pid=no
+ExecStart=@sbindir@/pdns_server --guardian=no --daemon=no --disable-syslog --log-timestamp=no --write-pid=no
 Restart=on-failure
 RestartSec=1
 StartLimitInterval=0
index 6ea920f863916ed6221021ab69b2617668fde0cc..1419a7c7710befde4d11d3f4d41aa17265120fec 100644 (file)
@@ -2761,6 +2761,7 @@ static int serviceMain(int argc, char*argv[])
 {
   L.setName(s_programname);
   L.disableSyslog(::arg().mustDo("disable-syslog"));
+  L.setTimestamps(::arg().mustDo("log-timestamp"));
 
   if(!::arg()["logging-facility"].empty()) {
     int val=logFacilityToLOG(::arg().asNum("logging-facility") );
@@ -3250,6 +3251,7 @@ int main(int argc, char **argv)
     ::arg().setSwitch("write-pid","Write a PID file")="yes";
     ::arg().set("loglevel","Amount of logging. Higher is more. Do not set below 3")="6";
     ::arg().set("disable-syslog","Disable logging to syslog, useful when running inside a supervisor that logs stdout")="no";
+    ::arg().set("log-timestamp","Print timestamps in log lines, useful to disable when running with a tool that timestamps stdout already")="yes";
     ::arg().set("log-common-errors","If we should log rather common errors")="no";
     ::arg().set("chroot","switch to chroot jail")="";
     ::arg().set("setgid","If set, change group id to this gid for more security")="";
index e51d57a334eb832ee2fea1dc723b3d9d835a4455..841bbcc741df128406c17b96b74c68f4c80b7d4e 100644 (file)
@@ -467,6 +467,7 @@ int main(int argc, char **argv)
 
     L.setLoglevel((Logger::Urgency)(::arg().asNum("loglevel")));
     L.disableSyslog(::arg().mustDo("disable-syslog"));
+    L.setTimestamps(::arg().mustDo("log-timestamp"));
     L.toConsole((Logger::Urgency)(::arg().asNum("loglevel")));  
 
     if(::arg().mustDo("help") || ::arg().mustDo("config")) {
index 3e8af129de3dd6db9e930e3e69fe7b8e04d61dde..8940d8eb65b173928da1aa6b47619bee0a95640e 100644 (file)
@@ -538,6 +538,22 @@ It is highly recommended to bind to explicit addresses.
 Local port to bind to.
 If an address in `local-address`_ does not have an explicit port, this port is used.
 
+.. _setting-log-timestamp:
+
+``log-timestamp``
+-----------------
+
+.. versionadded:: 4.1.0
+
+- Bool
+- Default: yes
+
+When printing log lines to stdout, prefix them with timestamps.
+Disable this if the process supervisor timestamps these lines already.
+
+.. note::
+  The systemd unit file supplied with the source code already disables timestamp printing
+
 .. _setting-non-local-bind:
 
 ``non-local-bind``
index ca38cb3ff2ceab3a0f54640b187b306a269cc409..4c0d61bf03ebd6abdc39221f849787df6e852b9e 100644 (file)
@@ -8,7 +8,7 @@ After=network-online.target
 
 [Service]
 Type=notify
-ExecStart=@sbindir@/pdns_recursor --daemon=no --write-pid=no --disable-syslog
+ExecStart=@sbindir@/pdns_recursor --daemon=no --write-pid=no --disable-syslog --log-timestamp=no
 Restart=on-failure
 StartLimitInterval=0
 PrivateTmp=true