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 [%5d.%d] %s %s:%d %s %s",
65 getpid(), get_parent_count(),
67 file, line, normal_color, trace);
69 ret = write(logfile_fd, all_trace, ret);
71 * If write failed, well, not much point in trying to print a
72 * trace about it.. So we just ignore the return value
76 int open_log_file(const char *logfile)
80 pr_info("Switching logging to file: %s\n", logfile);
82 fd = open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0666);
84 pr_err("Failed to open logfile %s: %m\n", logfile);
88 if (logfile_fd != STDERR_FILENO)
92 pr_info("Opened file %s for logging\n", logfile);