X-Git-Url: http://git.openpandora.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fpnd_logger.c;h=79b8558cabe154f8661c13cf8f8c96bb6cb2cf19;hb=e29a9532f576b7f7d0cd304cad5b2cc0c86f9645;hp=ebfd230385ab3f45dbe5f216962ea62626246b36;hpb=d116d5cf4e5eb58bbe2d5fdd4642ebe508f31711;p=pandora-libraries.git diff --git a/lib/pnd_logger.c b/lib/pnd_logger.c index ebfd230..79b8558 100644 --- a/lib/pnd_logger.c +++ b/lib/pnd_logger.c @@ -2,10 +2,13 @@ #include // va-args #include // malloc/free #include // strdup +#include #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 ); +}