pndnotifyd: fix some crashes
[pandora-libraries.git] / lib / pnd_logger.c
index 38a6586..79b8558 100644 (file)
@@ -2,11 +2,13 @@
 #include <stdarg.h> // va-args
 #include <stdlib.h> // malloc/free
 #include <string.h> // strdup
+#include <time.h>
 #include "pnd_logger.h"
 
-char *log_pretext = NULL;
-unsigned char log_filterlevel = 0;
-unsigned char log_flushafter = 0;
+static char *log_pretext = NULL;
+static unsigned char log_filterlevel = 0;
+static unsigned char log_flushafter = 0;
+static time_t log_first = 0;
 
 typedef enum {
   pndl_nil = 0,
@@ -120,10 +122,10 @@ static void pnd_log_emit ( unsigned char level, char *message ) {
     case pndl_stream:
       // pretext
       if ( log_pretext ) {
-       fprintf ( log_targets [ i ].stream, "%s\t", log_pretext );
+       fprintf ( log_targets [ i ].stream, "%s ", log_pretext );
       }
       // log level
-      fprintf ( log_targets [ i ].stream, "%u\t", level );
+      fprintf ( log_targets [ i ].stream, "%u %u\t", level, (unsigned int) (time ( NULL ) - log_first) );
       // message
       if ( message ) {
        fprintf ( log_targets [ i ].stream, "%s", message );
@@ -153,6 +155,10 @@ static void pnd_log_emit ( unsigned char level, char *message ) {
 
 unsigned char pnd_log ( unsigned char level, char *fmt, ... ) {
 
+  if ( log_first == 0 ) {
+    log_first = time ( NULL );
+  }
+
   if ( level == PND_LOG_FORCE ) {
     // always proceed
   } else if ( level < log_filterlevel ) {