]> pilppa.org Git - libplp.git/commitdiff
updates to log_debug/info/warning/error functions
authorMika Laitio <lamikr@pilppa.org>
Tue, 17 May 2011 20:01:07 +0000 (23:01 +0300)
committerMika Laitio <lamikr@pilppa.org>
Tue, 17 May 2011 20:01:07 +0000 (23:01 +0300)
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 <lamikr@pilppa.org>
src/log.h
src_test/test_logs.c

index 17596df25c93a206fd27da21f8063804d1267219..c88b6c8bc4dde2ce3f0ebdcd779a51c4a12b4cb9 100644 (file)
--- a/src/log.h
+++ b/src/log.h
@@ -10,9 +10,9 @@
 
 #include <stdio.h>
 
-#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_ */
index 1b0059c77fd3d26e780b2839755d076b797a43d5..4b8fca64d2dcab5b9f8b0697fdd5543890cf3b6e 100644 (file)
@@ -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");