From: Richard Kettlewell Date: Sun, 5 Apr 2009 15:08:28 +0000 (+0100) Subject: disorder-playrtp now includes timestamps in its log output (which X-Git-Tag: 5.0~146 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/disorder/commitdiff_plain/9d7a61297cb7263160d85a12d445fc1897fbfa80?hp=d3676ebc9f29f52b68eb1beb794cf710e04dcad6 disorder-playrtp now includes timestamps in its log output (which includes error messages); the reasoning being that timing information may be especially useful when debugging it. The server logs to syslog, which already has timestamps. Other programs could easily have this feature enabled if necessary. --- diff --git a/clients/playrtp.c b/clients/playrtp.c index c6f0ad9..f566409 100644 --- a/clients/playrtp.c +++ b/clients/playrtp.c @@ -592,6 +592,9 @@ int main(int argc, char **argv) { .ai_protocol = IPPROTO_UDP }; + /* Timing information is often important to debugging playrtp, so we include + * timestamps in the logs */ + logdate = 1; mem_init(); if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale"); backend = uaudio_apis[0]; diff --git a/lib/log.c b/lib/log.c index 3f57073..95a89a1 100644 --- a/lib/log.c +++ b/lib/log.c @@ -38,6 +38,7 @@ #include #include #include +#include #include "log.h" #include "disorder.h" @@ -66,6 +67,9 @@ const char *progname; /** @brief Filename for debug messages */ const char *debug_filename; +/** @brief Set to include timestamps in log messages */ +int logdate; + /** @brief Line number for debug messages */ int debug_lineno; @@ -121,6 +125,14 @@ static void logfp(int pri, const char *msg, void *user) { if(progname) fprintf(fp, "%s: ", progname); + if(logdate) { + char timebuf[64]; + struct tm *tm; + gettimeofday(&tv, 0); + tm = localtime(&tv.tv_sec); + strftime(timebuf, sizeof timebuf, "%Y-%m-%d %H:%M:%S %Z", tm); + fprintf(fp, "%s: ", timebuf); + } if(pri <= LOG_ERR) fputs("ERROR: ", fp); else if(pri < LOG_DEBUG) diff --git a/lib/log.h b/lib/log.h index 4d91008..5d39732 100644 --- a/lib/log.h +++ b/lib/log.h @@ -67,6 +67,7 @@ extern struct log_output log_stderr, log_syslog, *log_default; extern const char *debug_filename; extern int debug_lineno; +extern int logdate; #define D(x) do { \ if(debugging) { \