#include #include #include #include "process.h" #include "debug.h" const char red_color[] = { 0x1b, 0x5b, 0x30, 0x3b, 0x33, 0x31, 0x3b, 0x34, 0x30, 0x6d, 0x0, }; const char green_color[] = { 0x1b, 0x5b, 0x30, 0x3b, 0x33, 0x32, 0x3b, 0x34, 0x30, 0x6d, 0x0, }; const char normal_color[] = { 0x1b, 0x5b, 0x30, 0x3b, 0x33, 0x37, 0x3b, 0x34, 0x30, 0x6d, 0x0, }; int trace_level = 1; static const char *assign_color(int color) { switch (color) { case 1: return red_color; case 2: return green_color; default: return normal_color; } } void print_trace(const char *file, int line, int color, int l, const char *fmt, ...) { va_list args; time_t t = time(0); char time[32]; char trace[1024]; const char *color_str = assign_color(color); 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)); fprintf(stderr, "%s%s [%5d.%d] %s:%d %s %s", color_str, time, getpid(), get_parent_count(), file, line, normal_color, trace); fflush(stderr); }