]> git.itanic.dy.fi Git - rrdd/commitdiff
Autoindent debug messages according to parent count
authorTimo Kokkonen <kaapeli@ee.oulu.fi>
Sun, 18 May 2008 17:04:47 +0000 (20:04 +0300)
committerTimo Kokkonen <kaapeli@ee.oulu.fi>
Sun, 18 May 2008 17:04:47 +0000 (20:04 +0300)
debug.h

diff --git a/debug.h b/debug.h
index eff099321185b55f3ff20339f09d4e0b9a92e0eb..5c8a56999ca39c0e250091afa15fdc7a365ab56f 100644 (file)
--- a/debug.h
+++ b/debug.h
@@ -2,17 +2,29 @@
 #define __DEBUG_H
 
 #include <unistd.h>
+#include "process.h"
 
 extern const char red_color[];
 extern const char green_color[];
 extern const char normal_color[];
 
-#define pr_err(fmt, arg...) \
-       fprintf(stderr, "%s[%d] %s:%d Error %s" fmt, red_color, getpid(), \
-               __FILE__, __LINE__, normal_color, ##arg)
+#define pr_info(fmt, arg...)                                           \
+       do {                                                            \
+               char indent[16] = { ' ' };                              \
+               indent[get_parent_count()] = 0;                         \
+               fprintf(stderr, "%s%s[%d] %s:%d %s"                     \
+                       fmt, indent, green_color, getpid(),             \
+                       __FILE__, __LINE__, normal_color, ##arg);       \
+       } while (0)
 
-#define pr_info(fmt, arg...) \
-       printf("%s[%d] %s:%d %s" fmt, green_color, getpid(), \
-              __FILE__, __LINE__, normal_color, ##arg)
+
+#define pr_err(fmt, arg...)                                            \
+       do {                                                            \
+               char indent[16] = { ' ' };                              \
+               indent[get_parent_count()] = 0;                         \
+               fprintf(stderr, "%s%s[%d] %s:%d Error %s"               \
+                       fmt, indent, red_color, getpid(),               \
+                       __FILE__, __LINE__, normal_color, ##arg);       \
+       } while (0)
 
 #endif