+#include <time.h>
+#include <unistd.h>
+#include <stdarg.h>
+#include "process.h"
+
#include "debug.h"
const char red_color[] = {
const char normal_color[] = {
0x1b, 0x5b, 0x30, 0x3b, 0x33, 0x37, 0x3b, 0x34, 0x30, 0x6d, 0x0,
};
+
+int trace_level = 1;
+
+void print_trace(const char *file, int line, int color, int l,
+ const char *fmt, ...)
+{
+ va_list args;
+ time_t t = time(0);
+ char indent[16] = { " " };
+ char time[32];
+ char trace[1024];
+
+ if (l > trace_level)
+ return;
+
+ va_start(args, fmt);
+ vsnprintf(trace, sizeof(trace), fmt, args);
+ va_end(args);
+
+ strftime(time, sizeof(time), "%d.%m.%Y %T ", localtime(&t));
+ indent[get_parent_count()] = 0;
+
+ fprintf(stderr, "%s%s %s[%5d.%d] %s:%d %s %s",
+ green_color, time, indent,
+ getpid(), get_parent_count(),
+ file, line, normal_color, trace);
+ fflush(stderr);
+}
#ifndef __DEBUG_H
#define __DEBUG_H
-#include <time.h>
-#include <unistd.h>
-#include "process.h"
-
extern const char red_color[];
extern const char green_color[];
extern const char normal_color[];
-#define pr_info(fmt, arg...) \
- do { \
- time_t t = time(0); \
- char indent[16] = { " " }; \
- char time[32]; \
- \
- strftime(time, sizeof(time), "%d.%m.%Y %T ", \
- localtime(&t)); \
- indent[get_parent_count()] = 0; \
- \
- fprintf(stderr, "%s%s %s[%5d.%d] %s:%d %s" \
- fmt, green_color, time, indent, \
- getpid(), get_parent_count(), \
- __FILE__, __LINE__, normal_color, ##arg); \
- fflush(stderr); \
- } while (0)
-
+void __attribute__ ((__format__ (__printf__, 5, 6)))
+print_trace(const char *file, int line, int color, int l,
+ const char *fmt, ...);
-#define pr_err(fmt, arg...) \
- do { \
- time_t t = time(0); \
- char indent[16] = { " " }; \
- char time[32]; \
- \
- strftime(time, sizeof(time), "%d.%m.%Y %T ", \
- localtime(&t)); \
- indent[get_parent_count()] = 0; \
- \
- fprintf(stderr, "%s%s %s[%5d.%d] %s:%d Error %s" \
- fmt, red_color, time, indent, \
- getpid(), get_parent_count(), \
- __FILE__, __LINE__, normal_color, ##arg); \
- fflush(stderr); \
- } while (0)
+#define pr_err(arg...) print_trace(__FILE__, __LINE__, 1, 0, arg)
+#define pr_info(arg...) print_trace(__FILE__, __LINE__, 2, 1, arg)
#endif