New test for log changes
[yaz-moved-to-github.git] / src / log.c
index b68e308..f254466 100644 (file)
--- a/src/log.c
+++ b/src/log.c
@@ -1,5 +1,5 @@
 /* This file is part of the YAZ toolkit.
- * Copyright (C) 1995-2011 Index Data
+ * Copyright (C) 1995-2012 Index Data
  * See the file LICENSE for details.
  */
 
 #endif
 #include <stdio.h>
 #include <stdlib.h>
-#include <ctype.h>
 #include <string.h>
 #include <stdarg.h>
 #include <errno.h>
 #include <time.h>
+#include <yaz/yaz-iconv.h>
 #include <yaz/errno.h>
 #include <yaz/thread_id.h>
 #include <yaz/log.h>
@@ -60,6 +60,7 @@ static char l_old_default_format[] = "%H:%M:%S-%d/%m";
 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;
 
@@ -97,7 +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 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)
 {
@@ -438,6 +440,9 @@ static void yaz_log_to_file(int level, const char *log_message)
     }
 }
 
+static int is_module_log(int level) {
+    return level >= module_logs;
+}
 void yaz_log(int level, const char *fmt, ...)
 {
     va_list ap;
@@ -448,6 +453,19 @@ void yaz_log(int level, const char *fmt, ...)
     internal_log_init();
     if (!(level & l_level))
         return;
+    /* 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, module_no;
+        module_log_level = level & YLOG_LEVEL_MASK;
+        module_no = level &(~( module_logs-1)); 
+        if (!(module_no & l_level))
+            return ;
+        if (module_log_level != 0) {
+            if (!(module_log_level & l_level))
+                    return;
+        }
+    }
     va_start(ap, fmt);
 
     /* 30 is enough for our 'rest of output' message */
@@ -575,7 +593,7 @@ int yaz_log_mask_str_x(const char *str, int level)
             negated = 1;
             str++;
         }
-        if (isdigit(*(unsigned char *) str))
+        if (yaz_isdigit(*str))
         {
             level = atoi(str);
         }