From: Stefan Schubert Date: Tue, 27 Nov 2007 09:53:27 +0000 (+0000) Subject: adding a callback definition for logging X-Git-Tag: BASE-SuSE-Code-12_1-Branch~1093 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0089626560eb5ecd80a384146c64f47d3128cfca;p=platform%2Fupstream%2Flibsolv.git adding a callback definition for logging --- diff --git a/src/sat_debug.c b/src/sat_debug.c index 5c7daba..fcf462c 100644 --- a/src/sat_debug.c +++ b/src/sat_debug.c @@ -21,7 +21,14 @@ 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); } } diff --git a/src/sat_debug.h b/src/sat_debug.h index b376445..a354530 100644 --- a/src/sat_debug.h +++ b/src/sat_debug.h @@ -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 */