|
30 | 30 |
|
31 | 31 | #include "ur_client_library/default_log_handler.h" |
32 | 32 | #include <stdio.h> |
| 33 | +#include <chrono> |
33 | 34 |
|
34 | 35 | namespace urcl |
35 | 36 | { |
36 | 37 | DefaultLogHandler::DefaultLogHandler() = default; |
37 | 38 |
|
38 | 39 | void DefaultLogHandler::log(const char* file, int line, LogLevel loglevel, const char* log) |
39 | 40 | { |
| 41 | + time_t timestamp = time(NULL); |
| 42 | + double time = |
| 43 | + std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()) |
| 44 | + .count() / |
| 45 | + 1000.0; |
| 46 | + |
| 47 | + const char color_red[] = "\033[31m"; |
| 48 | + const char color_orange[] = "\033[93m"; |
| 49 | + const char color_none[] = "\033[39m"; |
40 | 50 | switch (loglevel) |
41 | 51 | { |
42 | 52 | case LogLevel::INFO: |
43 | | - printf("%s%s %i: %s \n", "INFO ", file, line, log); |
| 53 | + printf("%f: %s%s %i: %s \n", time, "INFO ", file, line, log); |
44 | 54 | break; |
45 | 55 | case LogLevel::DEBUG: |
46 | 56 | printf("%s%s %i: %s \n", "DEBUG ", file, line, log); |
47 | 57 | break; |
48 | 58 | case LogLevel::WARN: |
49 | | - printf("%s%s %i: %s \n", "WARN ", file, line, log); |
| 59 | + printf("%s%f: %s%s %i: %s%s\n", color_orange, time, "WARN ", file, line, log, color_none); |
50 | 60 | break; |
51 | 61 | case LogLevel::ERROR: |
52 | | - printf("%s%s %i: %s \n", "ERROR ", file, line, log); |
| 62 | + printf("%s%f: %s%s %i: %s%s\n", color_red, time, "ERROR ", file, line, log, color_none); |
53 | 63 | break; |
54 | 64 | case LogLevel::FATAL: |
55 | | - printf("%s%s %i: %s \n", "FATAL ", file, line, log); |
| 65 | + printf("%s%s%s %i: %s%s\n", "FATAL ", color_red, file, line, log, color_none); |
56 | 66 | break; |
57 | 67 | default: |
58 | 68 | break; |
|
0 commit comments