From 9d7a61297cb7263160d85a12d445fc1897fbfa80 Mon Sep 17 00:00:00 2001 Message-Id: <9d7a61297cb7263160d85a12d445fc1897fbfa80.1716360094.git.mdw@distorted.org.uk> From: Mark Wooding Date: Sun, 5 Apr 2009 16:08:28 +0100 Subject: [PATCH] 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. Organization: Straylight/Edgeware From: Richard Kettlewell The server logs to syslog, which already has timestamps. Other programs could easily have this feature enabled if necessary. --- clients/playrtp.c | 3 +++ lib/log.c | 12 ++++++++++++ lib/log.h | 1 + 3 files changed, 16 insertions(+) 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) { \ -- [mdw]