From f16480506a6cd3f23f82b940a617e4138f9362ac Mon Sep 17 00:00:00 2001 From: skeezix Date: Mon, 21 Dec 2009 13:13:50 -0500 Subject: [PATCH] Added a flush option to pnd_log, which makes log-to-stdout useful --- apps/pndnotifyd.c | 1 + include/pnd_logger.h | 2 ++ lib/pnd_logger.c | 9 +++++++++ 3 files changed, 12 insertions(+) diff --git a/apps/pndnotifyd.c b/apps/pndnotifyd.c index 66bd43d..73fcbab 100644 --- a/apps/pndnotifyd.c +++ b/apps/pndnotifyd.c @@ -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() ); } diff --git a/include/pnd_logger.h b/include/pnd_logger.h index d9fcc19..6db1aed 100644 --- a/include/pnd_logger.h +++ b/include/pnd_logger.h @@ -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. diff --git a/lib/pnd_logger.c b/lib/pnd_logger.c index ebfd230..96b3e3f 100644 --- a/lib/pnd_logger.c +++ b/lib/pnd_logger.c @@ -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; -- 2.39.5