diff options
Diffstat (limited to 'src/common/logging/text_formatter.cpp')
| -rw-r--r-- | src/common/logging/text_formatter.cpp | 52 |
1 files changed, 31 insertions, 21 deletions
diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp index de195b0f7..955358553 100644 --- a/src/common/logging/text_formatter.cpp +++ b/src/common/logging/text_formatter.cpp | |||
| @@ -6,8 +6,8 @@ | |||
| 6 | #include <cstdio> | 6 | #include <cstdio> |
| 7 | 7 | ||
| 8 | #ifdef _WIN32 | 8 | #ifdef _WIN32 |
| 9 | # define WIN32_LEAN_AND_MEAN | 9 | #define WIN32_LEAN_AND_MEAN |
| 10 | # include <Windows.h> | 10 | #include <Windows.h> |
| 11 | #endif | 11 | #endif |
| 12 | 12 | ||
| 13 | #include "common/logging/backend.h" | 13 | #include "common/logging/backend.h" |
| @@ -44,15 +44,14 @@ const char* TrimSourcePath(const char* path, const char* root) { | |||
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | void FormatLogMessage(const Entry& entry, char* out_text, size_t text_len) { | 46 | void FormatLogMessage(const Entry& entry, char* out_text, size_t text_len) { |
| 47 | unsigned int time_seconds = static_cast<unsigned int>(entry.timestamp.count() / 1000000); | 47 | unsigned int time_seconds = static_cast<unsigned int>(entry.timestamp.count() / 1000000); |
| 48 | unsigned int time_fractional = static_cast<unsigned int>(entry.timestamp.count() % 1000000); | 48 | unsigned int time_fractional = static_cast<unsigned int>(entry.timestamp.count() % 1000000); |
| 49 | 49 | ||
| 50 | const char* class_name = GetLogClassName(entry.log_class); | 50 | const char* class_name = GetLogClassName(entry.log_class); |
| 51 | const char* level_name = GetLevelName(entry.log_level); | 51 | const char* level_name = GetLevelName(entry.log_level); |
| 52 | 52 | ||
| 53 | snprintf(out_text, text_len, "[%4u.%06u] %s <%s> %s: %s", | 53 | snprintf(out_text, text_len, "[%4u.%06u] %s <%s> %s: %s", time_seconds, time_fractional, |
| 54 | time_seconds, time_fractional, class_name, level_name, | 54 | class_name, level_name, TrimSourcePath(entry.location.c_str()), entry.message.c_str()); |
| 55 | TrimSourcePath(entry.location.c_str()), entry.message.c_str()); | ||
| 56 | } | 55 | } |
| 57 | 56 | ||
| 58 | void PrintMessage(const Entry& entry) { | 57 | void PrintMessage(const Entry& entry) { |
| @@ -72,38 +71,50 @@ void PrintColoredMessage(const Entry& entry) { | |||
| 72 | WORD color = 0; | 71 | WORD color = 0; |
| 73 | switch (entry.log_level) { | 72 | switch (entry.log_level) { |
| 74 | case Level::Trace: // Grey | 73 | case Level::Trace: // Grey |
| 75 | color = FOREGROUND_INTENSITY; break; | 74 | color = FOREGROUND_INTENSITY; |
| 75 | break; | ||
| 76 | case Level::Debug: // Cyan | 76 | case Level::Debug: // Cyan |
| 77 | color = FOREGROUND_GREEN | FOREGROUND_BLUE; break; | 77 | color = FOREGROUND_GREEN | FOREGROUND_BLUE; |
| 78 | break; | ||
| 78 | case Level::Info: // Bright gray | 79 | case Level::Info: // Bright gray |
| 79 | color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; break; | 80 | color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE; |
| 81 | break; | ||
| 80 | case Level::Warning: // Bright yellow | 82 | case Level::Warning: // Bright yellow |
| 81 | color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; break; | 83 | color = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; |
| 84 | break; | ||
| 82 | case Level::Error: // Bright red | 85 | case Level::Error: // Bright red |
| 83 | color = FOREGROUND_RED | FOREGROUND_INTENSITY; break; | 86 | color = FOREGROUND_RED | FOREGROUND_INTENSITY; |
| 87 | break; | ||
| 84 | case Level::Critical: // Bright magenta | 88 | case Level::Critical: // Bright magenta |
| 85 | color = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY; break; | 89 | color = FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY; |
| 90 | break; | ||
| 86 | case Level::Count: | 91 | case Level::Count: |
| 87 | UNREACHABLE(); | 92 | UNREACHABLE(); |
| 88 | } | 93 | } |
| 89 | 94 | ||
| 90 | SetConsoleTextAttribute(console_handle, color); | 95 | SetConsoleTextAttribute(console_handle, color); |
| 91 | #else | 96 | #else |
| 92 | # define ESC "\x1b" | 97 | #define ESC "\x1b" |
| 93 | const char* color = ""; | 98 | const char* color = ""; |
| 94 | switch (entry.log_level) { | 99 | switch (entry.log_level) { |
| 95 | case Level::Trace: // Grey | 100 | case Level::Trace: // Grey |
| 96 | color = ESC "[1;30m"; break; | 101 | color = ESC "[1;30m"; |
| 102 | break; | ||
| 97 | case Level::Debug: // Cyan | 103 | case Level::Debug: // Cyan |
| 98 | color = ESC "[0;36m"; break; | 104 | color = ESC "[0;36m"; |
| 105 | break; | ||
| 99 | case Level::Info: // Bright gray | 106 | case Level::Info: // Bright gray |
| 100 | color = ESC "[0;37m"; break; | 107 | color = ESC "[0;37m"; |
| 108 | break; | ||
| 101 | case Level::Warning: // Bright yellow | 109 | case Level::Warning: // Bright yellow |
| 102 | color = ESC "[1;33m"; break; | 110 | color = ESC "[1;33m"; |
| 111 | break; | ||
| 103 | case Level::Error: // Bright red | 112 | case Level::Error: // Bright red |
| 104 | color = ESC "[1;31m"; break; | 113 | color = ESC "[1;31m"; |
| 114 | break; | ||
| 105 | case Level::Critical: // Bright magenta | 115 | case Level::Critical: // Bright magenta |
| 106 | color = ESC "[1;35m"; break; | 116 | color = ESC "[1;35m"; |
| 117 | break; | ||
| 107 | case Level::Count: | 118 | case Level::Count: |
| 108 | UNREACHABLE(); | 119 | UNREACHABLE(); |
| 109 | } | 120 | } |
| @@ -117,8 +128,7 @@ void PrintColoredMessage(const Entry& entry) { | |||
| 117 | SetConsoleTextAttribute(console_handle, original_info.wAttributes); | 128 | SetConsoleTextAttribute(console_handle, original_info.wAttributes); |
| 118 | #else | 129 | #else |
| 119 | fputs(ESC "[0m", stderr); | 130 | fputs(ESC "[0m", stderr); |
| 120 | # undef ESC | 131 | #undef ESC |
| 121 | #endif | 132 | #endif |
| 122 | } | 133 | } |
| 123 | |||
| 124 | } | 134 | } |