12 const char red_color[] = {
13 0x1b, 0x5b, 0x30, 0x3b, 0x33, 0x31, 0x3b, 0x34, 0x30, 0x6d, 0x0,
16 const char green_color[] = {
17 0x1b, 0x5b, 0x30, 0x3b, 0x33, 0x32, 0x3b, 0x34, 0x30, 0x6d, 0x0,
20 const char normal_color[] = {
21 0x1b, 0x5b, 0x30, 0x3b, 0x33, 0x37, 0x3b, 0x34, 0x30, 0x6d, 0x0,
24 int trace_level = TRACE_INFO;
25 static int logfile_fd = STDERR_FILENO;
27 static const char *assign_color(int color)
39 void print_trace(const char *file, int line, int color, int l,
48 const char *color_str = assign_color(color);
55 vsnprintf(trace, sizeof(trace), fmt, args);
58 strftime(time, sizeof(time), "%d.%m.%Y %T", localtime(&t));
60 pthread_getname_np(pthread_self(), thread_name, sizeof(thread_name));
62 ret = snprintf(all_trace, sizeof(all_trace),
63 "%s%s [%s] %s:%d %s %s",
66 file, line, normal_color, trace);
68 ret = write(logfile_fd, all_trace, ret);
70 * If write failed, well, not much point in trying to print a
71 * trace about it.. So we just ignore the return value
75 int open_log_file(const char *logfile)
79 pr_info("Switching logging to file: %s\n", logfile);
81 fd = open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0666);
83 pr_err("Failed to open logfile %s: %m\n", logfile);
87 if (logfile_fd != STDERR_FILENO)
91 pr_info("Opened file %s for logging\n", logfile);