From: Dennis Schafroth Date: Tue, 22 May 2012 16:34:18 +0000 (+0000) Subject: Module logging: X-Git-Url: http://jsfdemo.indexdata.com/cgi-bin?a=commitdiff_plain;h=55828a604917e226a1017a80917b7e6f2e3a3d5a;p=yaz-moved-to-github.git Module logging: - Called without log level (debug,log,warn,fatal) then log. Existing module logging will work. - Called with a log level, then only log if that log level is enabled. A futher refinement could be to have independant log level. --- diff --git a/src/log.c b/src/log.c index 7d03b8b..d80974c 100644 --- a/src/log.c +++ b/src/log.c @@ -61,7 +61,6 @@ static char l_new_default_format[] = "%Y%m%d-%H%M%S"; #define TIMEFORMAT_LEN 50 #define TID_LEN 30 #define YLOG_LEVEL_MASK (YLOG_FATAL | YLOG_WARN | YLOG_LOG | YLOG_DEBUG ) - static char l_custom_format[TIMEFORMAT_LEN] = ""; static char *l_actual_format = l_old_default_format; @@ -99,8 +98,8 @@ static struct { /* the rest will be filled in if the user defines dynamic modules*/ }; -static unsigned int next_log_bit = YLOG_LAST_BIT<<1; /* first dynamic bit */ -static unsigned int module_logs = YLOG_LAST_BIT<<1; /* first dynamic bit */ +static unsigned int next_log_bit = YLOG_LAST_BIT<<1; /* next dynamic bit */ +static unsigned int module_logs = YLOG_LAST_BIT<<1; /* first dynamic bit */ static void internal_log_init(void) { @@ -457,8 +456,13 @@ void yaz_log(int level, const char *fmt, ...) /* Modules without log level should log (as before) */ /* if there exists a log level as well this should be respected. */ if (is_module_log(level)) { - int module_log_level; + int module_log_level, module_no, module_enabled; module_log_level = level & YLOG_LEVEL_MASK; + module_no = level &(~( module_logs-1)); + if (!(module_no & l_level)) + return ; + if (!module_enabled) + return ; if (module_log_level != 0) { if (!(module_log_level & l_level)) return;