#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,
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 ) {
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
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;
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 ) {
/* If that worked, return the string. */
if ( n > -1 && n < size ) {
- pnd_log_emit ( p );
+ pnd_log_emit ( level, p );
break;
}
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 );
+}