Added a flush option to pnd_log, which makes log-to-stdout useful
authorskeezix <skeezix@flotsam-vm.(none)>
Mon, 21 Dec 2009 18:13:50 +0000 (13:13 -0500)
committerskeezix <skeezix@flotsam-vm.(none)>
Mon, 21 Dec 2009 18:13:50 +0000 (13:13 -0500)
apps/pndnotifyd.c
include/pnd_logger.h
lib/pnd_logger.c

index 66bd43d..73fcbab 100644 (file)
@@ -113,6 +113,7 @@ int main ( int argc, char *argv[] ) {
     pnd_log_set_filter ( pndn_rem );
     pnd_log_set_pretext ( "pndnotifyd" );
     pnd_log_to_stdout();
+    pnd_log_set_flush ( 1 );
     pnd_log ( pndn_rem, "log level starting as %u", pnd_log_get_filter() );
   }
 
index d9fcc19..6db1aed 100644 (file)
@@ -30,6 +30,8 @@ unsigned char pnd_log_to_callback ( pnd_log_callback_f f, void *userdata ); // N
 
 // pass NULL to free any pre-text, otherwise it'll be kept. Passed in string is duplicated, so you may free yours if you like.
 void pnd_log_set_pretext ( char * );                                        // example: your app-name, or app+function-names, say.
+// after a write, do a flush; may only apply to streams, but will attempt to apply to all
+void pnd_log_set_flush ( unsigned char x );
 
 // set a 'filter level'; any log message of higher-or-equal level than current filter-level will be emitted. Thus, to remove filters
 // just set to level 0. Returns existing setting.
index ebfd230..96b3e3f 100644 (file)
@@ -6,6 +6,7 @@
 
 char *log_pretext = NULL;
 unsigned char log_filterlevel = 0;
+unsigned char log_flushafter = 0;
 
 typedef enum {
   pndl_nil = 0,
@@ -47,6 +48,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 ) {
@@ -120,6 +126,9 @@ void pnd_log_emit ( char *message ) {
        if ( strchr ( message, '\n' ) == NULL ) {
          fprintf ( log_targets [ i ].stream, "\n" );
        }
+       if ( log_flushafter ) {
+         fflush ( log_targets [ i ].stream );
+       }
       }
       break;