From: Mika Laitio Date: Tue, 17 May 2011 20:01:07 +0000 (+0300) Subject: updates to log_debug/info/warning/error functions X-Git-Url: http://pilppa.org/gitweb/?p=libplp.git;a=commitdiff_plain;h=6114bb5f252afb1e86682836b82db3e4c48213fe updates to log_debug/info/warning/error functions printout the log severity and function name from where the method was called by default. examples: [dbg] test_logging: debug message text... [inf] test_logging: info message text... [wrn] test_logging: warning message text... [err] test_logging: error message text... Signed-off-by: Mika Laitio --- diff --git a/src/log.h b/src/log.h index 17596df..c88b6c8 100644 --- a/src/log.h +++ b/src/log.h @@ -10,9 +10,9 @@ #include -#define log_debug(...) fprintf(stdout, __VA_ARGS__) -#define log_info(...) fprintf(stdout, __VA_ARGS__) -#define log_warning(...) fprintf(stderr, __VA_ARGS__) -#define log_error(...) fprintf(stderr, __VA_ARGS__) +#define log_debug(a, b...) fprintf(stdout, "[dbg] %s: " a, __FUNCTION__, ## b) +#define log_info(a, b...) fprintf(stdout, "[inf] %s: " a, __FUNCTION__, ## b) +#define log_warning(a, b...) fprintf(stderr, "[wrn] %s: " a, __FUNCTION__, ## b) +#define log_error(a, b...) fprintf(stderr, "[err] %s: " a, __FUNCTION__, ## b) #endif /* LOG_H_ */ diff --git a/src_test/test_logs.c b/src_test/test_logs.c index 1b0059c..4b8fca6 100644 --- a/src_test/test_logs.c +++ b/src_test/test_logs.c @@ -16,8 +16,8 @@ #include "../src/str_util.h" void test_logging() { - log_debug("debug"); - log_debug("debug v%d\n", 2); + log_debug("debug\n"); + log_debug("debug v%d.%d\n", 2, 3); log_info("info\n"); log_info("info v%d\n", 2); log_warning("warning\n");