Added my own evdev handler for dpad/dpadbuttons/nubs, works fantastic
[pandora-libraries.git] / lib / pnd_logger.c
index ebfd230..79b8558 100644 (file)
@@ -2,10 +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;
+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,
@@ -47,6 +50,11 @@ unsigned char pnd_log_get_filter ( void ) {
   return ( log_filterlevel );
 }
 
+void pnd_log_set_flush ( unsigned char x ) {
+  log_flushafter = x;
+  return;
+}
+
 void pnd_log_set_pretext ( char *pre ) {
 
   if ( log_pretext ) {
@@ -99,7 +107,7 @@ unsigned char pnd_log_max_targets ( void ) {
   return ( PND_LOG_MAX );
 }
 
-void pnd_log_emit ( char *message ) {
+static void pnd_log_emit ( unsigned char level, char *message ) {
   unsigned char i;
 
   // iterate across targets and attempt to emit
@@ -112,14 +120,21 @@ void pnd_log_emit ( char *message ) {
       break;
 
     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 %u\t", level, (unsigned int) (time ( NULL ) - log_first) );
+      // message
       if ( message ) {
        fprintf ( log_targets [ i ].stream, "%s", message );
        if ( strchr ( message, '\n' ) == NULL ) {
          fprintf ( log_targets [ i ].stream, "\n" );
        }
+       if ( log_flushafter ) {
+         fflush ( log_targets [ i ].stream );
+       }
       }
       break;
 
@@ -140,6 +155,10 @@ void pnd_log_emit ( 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 ) {
@@ -164,7 +183,7 @@ unsigned char pnd_log ( unsigned char level, char *fmt, ... ) {
 
     /* If that worked, return the string. */
     if ( n > -1 && n < size ) {
-      pnd_log_emit ( p );
+      pnd_log_emit ( level, p );
       break;
     }
 
@@ -188,3 +207,17 @@ unsigned char pnd_log ( unsigned char level, char *fmt, ... ) {
 
   return ( 1 );
 }
+
+
+static unsigned char _do_buried_logging = 0;
+void pnd_log_set_buried_logging ( unsigned char yesno ) {
+  _do_buried_logging = yesno;
+  return;
+}
+
+unsigned char pnd_log_do_buried_logging ( void ) {
+  if ( _do_buried_logging == 1 ) {
+    return ( 1 );
+  }
+  return ( 0 );
+}