From b18fa400b5b6c49f0255861a2bc7b3d3a64eae25 Mon Sep 17 00:00:00 2001 From: Pieter Lexis Date: Wed, 25 Oct 2017 11:17:58 +0200 Subject: [PATCH] Add log-timestamp option 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 | 16 ++++++++++++++++ pdns/common_startup.cc | 1 + pdns/logger.cc | 16 +++++++++------- pdns/logger.hh | 5 +++++ pdns/pdns.service.in | 2 +- pdns/pdns_recursor.cc | 2 ++ pdns/receiver.cc | 1 + pdns/recursordist/docs/settings.rst | 16 ++++++++++++++++ pdns/recursordist/pdns-recursor.service.in | 2 +- 9 files changed, 52 insertions(+), 9 deletions(-) diff --git a/docs/settings.rst b/docs/settings.rst index f67f185c2..10e36f551 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -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`` diff --git a/pdns/common_startup.cc b/pdns/common_startup.cc index 3bdc364f8..1070ce001 100644 --- a/pdns/common_startup.cc +++ b/pdns/common_startup.cc @@ -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"; diff --git a/pdns/logger.cc b/pdns/logger.cc index a720b88b4..01eb6e404 100644 --- a/pdns/logger.cc +++ b/pdns/logger.cc @@ -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 <