chiark / gitweb /
disorder-playrtp now includes timestamps in its log output (which
authorRichard Kettlewell <rjk@greenend.org.uk>
Sun, 5 Apr 2009 15:08:28 +0000 (16:08 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Sun, 5 Apr 2009 15:08:28 +0000 (16:08 +0100)
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.

clients/playrtp.c
lib/log.c
lib/log.h

index c6f0ad9ee2a9d3c0ca574cfa5f2cee6b1ca59e11..f566409fa4d9e6243a44a5839587f2dd6464f0d8 100644 (file)
@@ -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];
index 3f57073a1ef6bb2834c0f7b830c7f46df817a894..95a89a1b872f7df90616cd7c2ee18694434920c6 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
@@ -38,6 +38,7 @@
 #include <errno.h>
 #include <syslog.h>
 #include <sys/time.h>
+#include <time.h>
 
 #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)
index 4d91008edc3e0debc4a24d43dca200ba6add5f81..5d39732d7f2996adadd6b4a395af7f22fc837191 100644 (file)
--- 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) {                              \