From b252c6af5f14e743789530509ef651cebd6cf6c3 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Wed, 4 Jun 2008 19:23:42 +0200 Subject: [PATCH] Cleaned up interface of the logger. Also uninlined log_switch_{en,dis}able(). --- lib/lib.h | 15 ++++++++------- lib/log-file.c | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/lib/lib.h b/lib/lib.h index 1bd0b354..e93bdf6a 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -90,11 +90,10 @@ #define L_ERROR_R 'e' #define L_FATAL '!' /* die() */ -#define L_SIGHANDLER 0x10000 /* Avoid things which are unsafe in signal handlers */ +#define L_SIGHANDLER 0x10000 /* Avoid operations that are unsafe in signal handlers */ -extern char *log_title; /* NULL - print no title, default is log_progname */ +extern char *log_title; /* NULL - print no title, default is program name given to log_init() */ extern char *log_filename; /* Expanded name of the current log file */ -extern volatile int log_switch_nest; /* log_switch() nesting counter, increment to disable automatic switches */ extern int log_pid; /* 0 if shouldn't be logged */ extern int log_precise_timings; /* Include microsecond timestamps in log messages */ extern void (*log_die_hook)(void); @@ -106,8 +105,13 @@ void vmsg(uns cat, const char *fmt, va_list args); void die(const char *, ...) NONRET FORMAT_CHECK(printf,1,2); void log_init(const char *argv0); void log_file(const char *name); -void log_fork(void); +void log_fork(void); /* Call after fork() to update log_pid */ + +/* If the log name contains metacharacters for date and time, we switch the logs + * automatically whenever the name changes. You can disable it and switch explicitly. */ int log_switch(void); +void log_switch_disable(void); +void log_switch_enable(void); void assert_failed(const char *assertion, const char *file, int line) NONRET; void assert_failed_noinfo(void) NONRET; @@ -126,9 +130,6 @@ void assert_failed_noinfo(void) NONRET; #define DBG(x,y...) do { } while(0) #endif -static inline void log_switch_disable(void) { log_switch_nest++; } -static inline void log_switch_enable(void) { ASSERT(log_switch_nest); log_switch_nest--; } - /* Memory allocation */ #define xmalloc sh_xmalloc diff --git a/lib/log-file.c b/lib/log-file.c index 401e797c..0b22ff24 100644 --- a/lib/log-file.c +++ b/lib/log-file.c @@ -20,7 +20,7 @@ static char *log_name_patt; static int log_params; static int log_filename_size; -volatile int log_switch_nest; +static int log_switch_nest; static int do_log_switch(struct tm *tm) @@ -94,6 +94,19 @@ log_fork(void) log_pid = getpid(); } +void +log_switch_disable(void) +{ + log_switch_nest++; +} + +void +log_switch_enable(void) +{ + ASSERT(log_switch_nest); + log_switch_nest--; +} + #ifdef TEST int main(int argc, char **argv) -- 2.39.2