11 const char red_color[] = {
12 0x1b, 0x5b, 0x30, 0x3b, 0x33, 0x31, 0x3b, 0x34, 0x30, 0x6d, 0x0,
15 const char green_color[] = {
16 0x1b, 0x5b, 0x30, 0x3b, 0x33, 0x32, 0x3b, 0x34, 0x30, 0x6d, 0x0,
19 const char normal_color[] = {
20 0x1b, 0x5b, 0x30, 0x3b, 0x33, 0x37, 0x3b, 0x34, 0x30, 0x6d, 0x0,
23 int trace_level = TRACE_INFO;
24 static int logfile_fd = STDERR_FILENO;
26 static const char *assign_color(int color)
38 void print_trace(const char *file, int line, int color, int l,
46 const char *color_str = assign_color(color);
53 vsnprintf(trace, sizeof(trace), fmt, args);
56 strftime(time, sizeof(time), "%d.%m.%Y %T", localtime(&t));
58 ret = snprintf(all_trace, sizeof(all_trace),
59 "%s%s [%5d.%d] %s:%d %s %s",
61 getpid(), get_parent_count(),
62 file, line, normal_color, trace);
64 ret = write(logfile_fd, all_trace, ret);
66 * If write failed, well, not much point in trying to print a
67 * trace about it.. So we just ignore the return value
71 int open_log_file(const char *logfile)
75 pr_info("Switching logging to file: %s\n", logfile);
77 fd = open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0666);
79 pr_err("Failed to open logfile %s: %m\n", logfile);
83 if (logfile_fd != STDERR_FILENO)
87 pr_info("Opened file %s for logging\n", logfile);