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