adding a callback definition for logging
authorStefan Schubert <schubi@suse.de>
Tue, 27 Nov 2007 09:53:27 +0000 (09:53 +0000)
committerStefan Schubert <schubi@suse.de>
Tue, 27 Nov 2007 09:53:27 +0000 (09:53 +0000)
src/sat_debug.c
src/sat_debug.h

index 5c7daba..fcf462c 100644 (file)
 static DebugLevel debug_level = ERROR;
 // log file,function,line too
 static int sat_log_lineNr = 0;
+// Callback for logging
+SatDebugFn debugCallback = NULL;
 
+void
+sat_set_debugCallback (SatDebugFn callback)
+{
+    debugCallback = callback;
+}
 
 void
 sat_set_debug (DebugLevel level, int log_line_nr)
@@ -48,9 +55,15 @@ sat_debug (DebugLevel level, const char *format, ...)
     if (sat_debug_level() >= level) {
        if (sat_log_lineNr) {
            char pre[MAX_OUTPUT_LEN];
-           snprintf (pre, MAX_OUTPUT_LEN, "(%s, %s:%d) ", __FUNCTION__, __FILE__, __LINE__);
-           printf("%s", pre);
+           snprintf (pre, MAX_OUTPUT_LEN, "(%s, %s:%d) ", __FUNCTION__, __FILE__, __LINE__);       
+           if (debugCallback == NULL) 
+               printf("%s", pre);
+           else 
+               debugCallback (pre);
        }
-       printf ("%s", str);
+       if (debugCallback == NULL)     
+           printf ("%s", str);
+       else 
+           debugCallback (str);        
     }
 }
index b376445..a354530 100644 (file)
@@ -26,12 +26,15 @@ typedef enum {
     DEBUG_5  = 5
 } DebugLevel;
 
+// Callback for logging
+typedef void (*SatDebugFn) (char *logString);
+void sat_set_debugCallback (SatDebugFn callback);
+
 // debug level
 void sat_set_debug (DebugLevel level, int log_line_nr);
 DebugLevel sat_debug_level ();
 
+// logging a line
 void sat_debug (DebugLevel  level, const char *format, ...);
 
-
-
 #endif /* _SAT_DEBUG_H */