diff options
Diffstat (limited to 'src/common/logging')
| -rw-r--r-- | src/common/logging/backend.cpp | 139 | ||||
| -rw-r--r-- | src/common/logging/backend.h | 6 | ||||
| -rw-r--r-- | src/common/logging/filter.cpp | 7 | ||||
| -rw-r--r-- | src/common/logging/filter.h | 4 | ||||
| -rw-r--r-- | src/common/logging/log.h | 136 | ||||
| -rw-r--r-- | src/common/logging/text_formatter.cpp | 52 | ||||
| -rw-r--r-- | src/common/logging/text_formatter.h | 1 |
7 files changed, 181 insertions, 164 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 0b2fabec9..b3d6598e4 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp | |||
| @@ -16,73 +16,79 @@ | |||
| 16 | namespace Log { | 16 | namespace Log { |
| 17 | 17 | ||
| 18 | /// Macro listing all log classes. Code should define CLS and SUB as desired before invoking this. | 18 | /// Macro listing all log classes. Code should define CLS and SUB as desired before invoking this. |
| 19 | #define ALL_LOG_CLASSES() \ | 19 | #define ALL_LOG_CLASSES() \ |
| 20 | CLS(Log) \ | 20 | CLS(Log) \ |
| 21 | CLS(Common) \ | 21 | CLS(Common) \ |
| 22 | SUB(Common, Filesystem) \ | 22 | SUB(Common, Filesystem) \ |
| 23 | SUB(Common, Memory) \ | 23 | SUB(Common, Memory) \ |
| 24 | CLS(Core) \ | 24 | CLS(Core) \ |
| 25 | SUB(Core, ARM11) \ | 25 | SUB(Core, ARM11) \ |
| 26 | SUB(Core, Timing) \ | 26 | SUB(Core, Timing) \ |
| 27 | CLS(Config) \ | 27 | CLS(Config) \ |
| 28 | CLS(Debug) \ | 28 | CLS(Debug) \ |
| 29 | SUB(Debug, Emulated) \ | 29 | SUB(Debug, Emulated) \ |
| 30 | SUB(Debug, GPU) \ | 30 | SUB(Debug, GPU) \ |
| 31 | SUB(Debug, Breakpoint) \ | 31 | SUB(Debug, Breakpoint) \ |
| 32 | SUB(Debug, GDBStub) \ | 32 | SUB(Debug, GDBStub) \ |
| 33 | CLS(Kernel) \ | 33 | CLS(Kernel) \ |
| 34 | SUB(Kernel, SVC) \ | 34 | SUB(Kernel, SVC) \ |
| 35 | CLS(Service) \ | 35 | CLS(Service) \ |
| 36 | SUB(Service, SRV) \ | 36 | SUB(Service, SRV) \ |
| 37 | SUB(Service, FRD) \ | 37 | SUB(Service, FRD) \ |
| 38 | SUB(Service, FS) \ | 38 | SUB(Service, FS) \ |
| 39 | SUB(Service, ERR) \ | 39 | SUB(Service, ERR) \ |
| 40 | SUB(Service, APT) \ | 40 | SUB(Service, APT) \ |
| 41 | SUB(Service, GSP) \ | 41 | SUB(Service, GSP) \ |
| 42 | SUB(Service, AC) \ | 42 | SUB(Service, AC) \ |
| 43 | SUB(Service, AM) \ | 43 | SUB(Service, AM) \ |
| 44 | SUB(Service, PTM) \ | 44 | SUB(Service, PTM) \ |
| 45 | SUB(Service, LDR) \ | 45 | SUB(Service, LDR) \ |
| 46 | SUB(Service, NDM) \ | 46 | SUB(Service, NDM) \ |
| 47 | SUB(Service, NIM) \ | 47 | SUB(Service, NIM) \ |
| 48 | SUB(Service, NWM) \ | 48 | SUB(Service, NWM) \ |
| 49 | SUB(Service, CAM) \ | 49 | SUB(Service, CAM) \ |
| 50 | SUB(Service, CECD) \ | 50 | SUB(Service, CECD) \ |
| 51 | SUB(Service, CFG) \ | 51 | SUB(Service, CFG) \ |
| 52 | SUB(Service, DSP) \ | 52 | SUB(Service, DSP) \ |
| 53 | SUB(Service, DLP) \ | 53 | SUB(Service, DLP) \ |
| 54 | SUB(Service, HID) \ | 54 | SUB(Service, HID) \ |
| 55 | SUB(Service, SOC) \ | 55 | SUB(Service, SOC) \ |
| 56 | SUB(Service, IR) \ | 56 | SUB(Service, IR) \ |
| 57 | SUB(Service, Y2R) \ | 57 | SUB(Service, Y2R) \ |
| 58 | CLS(HW) \ | 58 | CLS(HW) \ |
| 59 | SUB(HW, Memory) \ | 59 | SUB(HW, Memory) \ |
| 60 | SUB(HW, LCD) \ | 60 | SUB(HW, LCD) \ |
| 61 | SUB(HW, GPU) \ | 61 | SUB(HW, GPU) \ |
| 62 | CLS(Frontend) \ | 62 | CLS(Frontend) \ |
| 63 | CLS(Render) \ | 63 | CLS(Render) \ |
| 64 | SUB(Render, Software) \ | 64 | SUB(Render, Software) \ |
| 65 | SUB(Render, OpenGL) \ | 65 | SUB(Render, OpenGL) \ |
| 66 | CLS(Audio) \ | 66 | CLS(Audio) \ |
| 67 | SUB(Audio, DSP) \ | 67 | SUB(Audio, DSP) \ |
| 68 | SUB(Audio, Sink) \ | 68 | SUB(Audio, Sink) \ |
| 69 | CLS(Loader) | 69 | CLS(Loader) |
| 70 | 70 | ||
| 71 | // GetClassName is a macro defined by Windows.h, grrr... | 71 | // GetClassName is a macro defined by Windows.h, grrr... |
| 72 | const char* GetLogClassName(Class log_class) { | 72 | const char* GetLogClassName(Class log_class) { |
| 73 | switch (log_class) { | 73 | switch (log_class) { |
| 74 | #define CLS(x) case Class::x: return #x; | 74 | #define CLS(x) \ |
| 75 | #define SUB(x, y) case Class::x##_##y: return #x "." #y; | 75 | case Class::x: \ |
| 76 | return #x; | ||
| 77 | #define SUB(x, y) \ | ||
| 78 | case Class::x##_##y: \ | ||
| 79 | return #x "." #y; | ||
| 76 | ALL_LOG_CLASSES() | 80 | ALL_LOG_CLASSES() |
| 77 | #undef CLS | 81 | #undef CLS |
| 78 | #undef SUB | 82 | #undef SUB |
| 79 | case Class::Count: | 83 | case Class::Count: |
| 80 | UNREACHABLE(); | 84 | UNREACHABLE(); |
| 81 | } | 85 | } |
| 82 | } | 86 | } |
| 83 | 87 | ||
| 84 | const char* GetLevelName(Level log_level) { | 88 | const char* GetLevelName(Level log_level) { |
| 85 | #define LVL(x) case Level::x: return #x | 89 | #define LVL(x) \ |
| 90 | case Level::x: \ | ||
| 91 | return #x | ||
| 86 | switch (log_level) { | 92 | switch (log_level) { |
| 87 | LVL(Trace); | 93 | LVL(Trace); |
| 88 | LVL(Debug); | 94 | LVL(Debug); |
| @@ -90,15 +96,14 @@ const char* GetLevelName(Level log_level) { | |||
| 90 | LVL(Warning); | 96 | LVL(Warning); |
| 91 | LVL(Error); | 97 | LVL(Error); |
| 92 | LVL(Critical); | 98 | LVL(Critical); |
| 93 | case Level::Count: | 99 | case Level::Count: |
| 94 | UNREACHABLE(); | 100 | UNREACHABLE(); |
| 95 | } | 101 | } |
| 96 | #undef LVL | 102 | #undef LVL |
| 97 | } | 103 | } |
| 98 | 104 | ||
| 99 | Entry CreateEntry(Class log_class, Level log_level, | 105 | Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, |
| 100 | const char* filename, unsigned int line_nr, const char* function, | 106 | const char* function, const char* format, va_list args) { |
| 101 | const char* format, va_list args) { | ||
| 102 | using std::chrono::steady_clock; | 107 | using std::chrono::steady_clock; |
| 103 | using std::chrono::duration_cast; | 108 | using std::chrono::duration_cast; |
| 104 | 109 | ||
| @@ -111,7 +116,8 @@ Entry CreateEntry(Class log_class, Level log_level, | |||
| 111 | entry.log_class = log_class; | 116 | entry.log_class = log_class; |
| 112 | entry.log_level = log_level; | 117 | entry.log_level = log_level; |
| 113 | 118 | ||
| 114 | snprintf(formatting_buffer.data(), formatting_buffer.size(), "%s:%s:%u", filename, function, line_nr); | 119 | snprintf(formatting_buffer.data(), formatting_buffer.size(), "%s:%s:%u", filename, function, |
| 120 | line_nr); | ||
| 115 | entry.location = std::string(formatting_buffer.data()); | 121 | entry.location = std::string(formatting_buffer.data()); |
| 116 | 122 | ||
| 117 | vsnprintf(formatting_buffer.data(), formatting_buffer.size(), format, args); | 123 | vsnprintf(formatting_buffer.data(), formatting_buffer.size(), format, args); |
| @@ -126,19 +132,16 @@ void SetFilter(Filter* new_filter) { | |||
| 126 | filter = new_filter; | 132 | filter = new_filter; |
| 127 | } | 133 | } |
| 128 | 134 | ||
| 129 | void LogMessage(Class log_class, Level log_level, | 135 | void LogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_nr, |
| 130 | const char* filename, unsigned int line_nr, const char* function, | 136 | const char* function, const char* format, ...) { |
| 131 | const char* format, ...) { | ||
| 132 | if (filter != nullptr && !filter->CheckMessage(log_class, log_level)) | 137 | if (filter != nullptr && !filter->CheckMessage(log_class, log_level)) |
| 133 | return; | 138 | return; |
| 134 | 139 | ||
| 135 | va_list args; | 140 | va_list args; |
| 136 | va_start(args, format); | 141 | va_start(args, format); |
| 137 | Entry entry = CreateEntry(log_class, log_level, | 142 | Entry entry = CreateEntry(log_class, log_level, filename, line_nr, function, format, args); |
| 138 | filename, line_nr, function, format, args); | ||
| 139 | va_end(args); | 143 | va_end(args); |
| 140 | 144 | ||
| 141 | PrintColoredMessage(entry); | 145 | PrintColoredMessage(entry); |
| 142 | } | 146 | } |
| 143 | |||
| 144 | } | 147 | } |
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index 795d42ebd..3fe88e4f6 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h | |||
| @@ -44,10 +44,8 @@ const char* GetLogClassName(Class log_class); | |||
| 44 | const char* GetLevelName(Level log_level); | 44 | const char* GetLevelName(Level log_level); |
| 45 | 45 | ||
| 46 | /// Creates a log entry by formatting the given source location, and message. | 46 | /// Creates a log entry by formatting the given source location, and message. |
| 47 | Entry CreateEntry(Class log_class, Level log_level, | 47 | Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, |
| 48 | const char* filename, unsigned int line_nr, const char* function, | 48 | const char* function, const char* format, va_list args); |
| 49 | const char* format, va_list args); | ||
| 50 | 49 | ||
| 51 | void SetFilter(Filter* filter); | 50 | void SetFilter(Filter* filter); |
| 52 | |||
| 53 | } | 51 | } |
diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp index 55cc8888a..186e0b621 100644 --- a/src/common/logging/filter.cpp +++ b/src/common/logging/filter.cpp | |||
| @@ -4,8 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | 6 | ||
| 7 | #include "common/logging/filter.h" | ||
| 8 | #include "common/logging/backend.h" | 7 | #include "common/logging/backend.h" |
| 8 | #include "common/logging/filter.h" | ||
| 9 | #include "common/string_util.h" | 9 | #include "common/string_util.h" |
| 10 | 10 | ||
| 11 | namespace Log { | 11 | namespace Log { |
| @@ -63,11 +63,11 @@ static Class GetClassByName(const It begin, const It end) { | |||
| 63 | } | 63 | } |
| 64 | 64 | ||
| 65 | bool Filter::ParseFilterRule(const std::string::const_iterator begin, | 65 | bool Filter::ParseFilterRule(const std::string::const_iterator begin, |
| 66 | const std::string::const_iterator end) { | 66 | const std::string::const_iterator end) { |
| 67 | auto level_separator = std::find(begin, end, ':'); | 67 | auto level_separator = std::find(begin, end, ':'); |
| 68 | if (level_separator == end) { | 68 | if (level_separator == end) { |
| 69 | LOG_ERROR(Log, "Invalid log filter. Must specify a log level after `:`: %s", | 69 | LOG_ERROR(Log, "Invalid log filter. Must specify a log level after `:`: %s", |
| 70 | std::string(begin, end).c_str()); | 70 | std::string(begin, end).c_str()); |
| 71 | return false; | 71 | return false; |
| 72 | } | 72 | } |
| 73 | 73 | ||
| @@ -95,5 +95,4 @@ bool Filter::ParseFilterRule(const std::string::const_iterator begin, | |||
| 95 | bool Filter::CheckMessage(Class log_class, Level level) const { | 95 | bool Filter::CheckMessage(Class log_class, Level level) const { |
| 96 | return static_cast<u8>(level) >= static_cast<u8>(class_levels[static_cast<size_t>(log_class)]); | 96 | return static_cast<u8>(level) >= static_cast<u8>(class_levels[static_cast<size_t>(log_class)]); |
| 97 | } | 97 | } |
| 98 | |||
| 99 | } | 98 | } |
diff --git a/src/common/logging/filter.h b/src/common/logging/filter.h index a2b4eca43..db526fead 100644 --- a/src/common/logging/filter.h +++ b/src/common/logging/filter.h | |||
| @@ -42,7 +42,8 @@ public: | |||
| 42 | * - `Service.FS:Trace` -- Sets the level of the Service.FS class to Trace. | 42 | * - `Service.FS:Trace` -- Sets the level of the Service.FS class to Trace. |
| 43 | */ | 43 | */ |
| 44 | void ParseFilterString(const std::string& filter_str); | 44 | void ParseFilterString(const std::string& filter_str); |
| 45 | bool ParseFilterRule(const std::string::const_iterator start, const std::string::const_iterator end); | 45 | bool ParseFilterRule(const std::string::const_iterator start, |
| 46 | const std::string::const_iterator end); | ||
| 46 | 47 | ||
| 47 | /// Matches class/level combination against the filter, returning true if it passed. | 48 | /// Matches class/level combination against the filter, returning true if it passed. |
| 48 | bool CheckMessage(Class log_class, Level level) const; | 49 | bool CheckMessage(Class log_class, Level level) const; |
| @@ -50,5 +51,4 @@ public: | |||
| 50 | private: | 51 | private: |
| 51 | std::array<Level, (size_t)Class::Count> class_levels; | 52 | std::array<Level, (size_t)Class::Count> class_levels; |
| 52 | }; | 53 | }; |
| 53 | |||
| 54 | } | 54 | } |
diff --git a/src/common/logging/log.h b/src/common/logging/log.h index c6910b1c7..a4b4750de 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h | |||
| @@ -28,71 +28,73 @@ typedef u8 ClassType; | |||
| 28 | /** | 28 | /** |
| 29 | * Specifies the sub-system that generated the log message. | 29 | * Specifies the sub-system that generated the log message. |
| 30 | * | 30 | * |
| 31 | * @note If you add a new entry here, also add a corresponding one to `ALL_LOG_CLASSES` in backend.cpp. | 31 | * @note If you add a new entry here, also add a corresponding one to `ALL_LOG_CLASSES` in |
| 32 | * backend.cpp. | ||
| 32 | */ | 33 | */ |
| 33 | enum class Class : ClassType { | 34 | enum class Class : ClassType { |
| 34 | Log, ///< Messages about the log system itself | 35 | Log, ///< Messages about the log system itself |
| 35 | Common, ///< Library routines | 36 | Common, ///< Library routines |
| 36 | Common_Filesystem, ///< Filesystem interface library | 37 | Common_Filesystem, ///< Filesystem interface library |
| 37 | Common_Memory, ///< Memory mapping and management functions | 38 | Common_Memory, ///< Memory mapping and management functions |
| 38 | Core, ///< LLE emulation core | 39 | Core, ///< LLE emulation core |
| 39 | Core_ARM11, ///< ARM11 CPU core | 40 | Core_ARM11, ///< ARM11 CPU core |
| 40 | Core_Timing, ///< CoreTiming functions | 41 | Core_Timing, ///< CoreTiming functions |
| 41 | Config, ///< Emulator configuration (including commandline) | 42 | Config, ///< Emulator configuration (including commandline) |
| 42 | Debug, ///< Debugging tools | 43 | Debug, ///< Debugging tools |
| 43 | Debug_Emulated, ///< Debug messages from the emulated programs | 44 | Debug_Emulated, ///< Debug messages from the emulated programs |
| 44 | Debug_GPU, ///< GPU debugging tools | 45 | Debug_GPU, ///< GPU debugging tools |
| 45 | Debug_Breakpoint, ///< Logging breakpoints and watchpoints | 46 | Debug_Breakpoint, ///< Logging breakpoints and watchpoints |
| 46 | Debug_GDBStub, ///< GDB Stub | 47 | Debug_GDBStub, ///< GDB Stub |
| 47 | Kernel, ///< The HLE implementation of the CTR kernel | 48 | Kernel, ///< The HLE implementation of the CTR kernel |
| 48 | Kernel_SVC, ///< Kernel system calls | 49 | Kernel_SVC, ///< Kernel system calls |
| 49 | Service, ///< HLE implementation of system services. Each major service | 50 | Service, ///< HLE implementation of system services. Each major service |
| 50 | /// should have its own subclass. | 51 | /// should have its own subclass. |
| 51 | Service_SRV, ///< The SRV (Service Directory) implementation | 52 | Service_SRV, ///< The SRV (Service Directory) implementation |
| 52 | Service_FRD, ///< The FRD (Friends) service | 53 | Service_FRD, ///< The FRD (Friends) service |
| 53 | Service_FS, ///< The FS (Filesystem) service implementation | 54 | Service_FS, ///< The FS (Filesystem) service implementation |
| 54 | Service_ERR, ///< The ERR (Error) port implementation | 55 | Service_ERR, ///< The ERR (Error) port implementation |
| 55 | Service_APT, ///< The APT (Applets) service | 56 | Service_APT, ///< The APT (Applets) service |
| 56 | Service_GSP, ///< The GSP (GPU control) service | 57 | Service_GSP, ///< The GSP (GPU control) service |
| 57 | Service_AC, ///< The AC (WiFi status) service | 58 | Service_AC, ///< The AC (WiFi status) service |
| 58 | Service_AM, ///< The AM (Application manager) service | 59 | Service_AM, ///< The AM (Application manager) service |
| 59 | Service_PTM, ///< The PTM (Power status & misc.) service | 60 | Service_PTM, ///< The PTM (Power status & misc.) service |
| 60 | Service_LDR, ///< The LDR (3ds dll loader) service | 61 | Service_LDR, ///< The LDR (3ds dll loader) service |
| 61 | Service_NDM, ///< The NDM (Network daemon manager) service | 62 | Service_NDM, ///< The NDM (Network daemon manager) service |
| 62 | Service_NIM, ///< The NIM (Network interface manager) service | 63 | Service_NIM, ///< The NIM (Network interface manager) service |
| 63 | Service_NWM, ///< The NWM (Network wlan manager) service | 64 | Service_NWM, ///< The NWM (Network wlan manager) service |
| 64 | Service_CAM, ///< The CAM (Camera) service | 65 | Service_CAM, ///< The CAM (Camera) service |
| 65 | Service_CECD, ///< The CECD (StreetPass) service | 66 | Service_CECD, ///< The CECD (StreetPass) service |
| 66 | Service_CFG, ///< The CFG (Configuration) service | 67 | Service_CFG, ///< The CFG (Configuration) service |
| 67 | Service_DSP, ///< The DSP (DSP control) service | 68 | Service_DSP, ///< The DSP (DSP control) service |
| 68 | Service_DLP, ///< The DLP (Download Play) service | 69 | Service_DLP, ///< The DLP (Download Play) service |
| 69 | Service_HID, ///< The HID (Human interface device) service | 70 | Service_HID, ///< The HID (Human interface device) service |
| 70 | Service_SOC, ///< The SOC (Socket) service | 71 | Service_SOC, ///< The SOC (Socket) service |
| 71 | Service_IR, ///< The IR service | 72 | Service_IR, ///< The IR service |
| 72 | Service_Y2R, ///< The Y2R (YUV to RGB conversion) service | 73 | Service_Y2R, ///< The Y2R (YUV to RGB conversion) service |
| 73 | HW, ///< Low-level hardware emulation | 74 | HW, ///< Low-level hardware emulation |
| 74 | HW_Memory, ///< Memory-map and address translation | 75 | HW_Memory, ///< Memory-map and address translation |
| 75 | HW_LCD, ///< LCD register emulation | 76 | HW_LCD, ///< LCD register emulation |
| 76 | HW_GPU, ///< GPU control emulation | 77 | HW_GPU, ///< GPU control emulation |
| 77 | Frontend, ///< Emulator UI | 78 | Frontend, ///< Emulator UI |
| 78 | Render, ///< Emulator video output and hardware acceleration | 79 | Render, ///< Emulator video output and hardware acceleration |
| 79 | Render_Software, ///< Software renderer backend | 80 | Render_Software, ///< Software renderer backend |
| 80 | Render_OpenGL, ///< OpenGL backend | 81 | Render_OpenGL, ///< OpenGL backend |
| 81 | Audio, ///< Audio emulation | 82 | Audio, ///< Audio emulation |
| 82 | Audio_DSP, ///< The HLE implementation of the DSP | 83 | Audio_DSP, ///< The HLE implementation of the DSP |
| 83 | Audio_Sink, ///< Emulator audio output backend | 84 | Audio_Sink, ///< Emulator audio output backend |
| 84 | Loader, ///< ROM loader | 85 | Loader, ///< ROM loader |
| 85 | 86 | ||
| 86 | Count ///< Total number of logging classes | 87 | Count ///< Total number of logging classes |
| 87 | }; | 88 | }; |
| 88 | 89 | ||
| 89 | /// Logs a message to the global logger. | 90 | /// Logs a message to the global logger. |
| 90 | void LogMessage(Class log_class, Level log_level, | 91 | void LogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_nr, |
| 91 | const char* filename, unsigned int line_nr, const char* function, | 92 | const char* function, |
| 92 | #ifdef _MSC_VER | 93 | #ifdef _MSC_VER |
| 93 | _Printf_format_string_ | 94 | _Printf_format_string_ |
| 94 | #endif | 95 | #endif |
| 95 | const char* format, ...) | 96 | const char* format, |
| 97 | ...) | ||
| 96 | #ifdef __GNUC__ | 98 | #ifdef __GNUC__ |
| 97 | __attribute__((format(printf, 6, 7))) | 99 | __attribute__((format(printf, 6, 7))) |
| 98 | #endif | 100 | #endif |
| @@ -100,17 +102,23 @@ void LogMessage(Class log_class, Level log_level, | |||
| 100 | 102 | ||
| 101 | } // namespace Log | 103 | } // namespace Log |
| 102 | 104 | ||
| 103 | #define LOG_GENERIC(log_class, log_level, ...) \ | 105 | #define LOG_GENERIC(log_class, log_level, ...) \ |
| 104 | ::Log::LogMessage(log_class, log_level, __FILE__, __LINE__, __func__, __VA_ARGS__) | 106 | ::Log::LogMessage(log_class, log_level, __FILE__, __LINE__, __func__, __VA_ARGS__) |
| 105 | 107 | ||
| 106 | #ifdef _DEBUG | 108 | #ifdef _DEBUG |
| 107 | #define LOG_TRACE( log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Trace, __VA_ARGS__) | 109 | #define LOG_TRACE(log_class, ...) \ |
| 110 | LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Trace, __VA_ARGS__) | ||
| 108 | #else | 111 | #else |
| 109 | #define LOG_TRACE( log_class, ...) (void(0)) | 112 | #define LOG_TRACE(log_class, ...) (void(0)) |
| 110 | #endif | 113 | #endif |
| 111 | 114 | ||
| 112 | #define LOG_DEBUG( log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Debug, __VA_ARGS__) | 115 | #define LOG_DEBUG(log_class, ...) \ |
| 113 | #define LOG_INFO( log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Info, __VA_ARGS__) | 116 | LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Debug, __VA_ARGS__) |
| 114 | #define LOG_WARNING( log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Warning, __VA_ARGS__) | 117 | #define LOG_INFO(log_class, ...) \ |
| 115 | #define LOG_ERROR( log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Error, __VA_ARGS__) | 118 | LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Info, __VA_ARGS__) |
| 116 | #define LOG_CRITICAL(log_class, ...) LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Critical, __VA_ARGS__) | 119 | #define LOG_WARNING(log_class, ...) \ |
| 120 | LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Warning, __VA_ARGS__) | ||
| 121 | #define LOG_ERROR(log_class, ...) \ | ||
| 122 | LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Error, __VA_ARGS__) | ||
| 123 | #define LOG_CRITICAL(log_class, ...) \ | ||
| 124 | LOG_GENERIC(::Log::Class::log_class, ::Log::Level::Critical, __VA_ARGS__) | ||
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 | } |
diff --git a/src/common/logging/text_formatter.h b/src/common/logging/text_formatter.h index 5b82f043f..0da102bc6 100644 --- a/src/common/logging/text_formatter.h +++ b/src/common/logging/text_formatter.h | |||
| @@ -28,5 +28,4 @@ void FormatLogMessage(const Entry& entry, char* out_text, size_t text_len); | |||
| 28 | void PrintMessage(const Entry& entry); | 28 | void PrintMessage(const Entry& entry); |
| 29 | /// Prints the same message as `PrintMessage`, but colored acoording to the severity level. | 29 | /// Prints the same message as `PrintMessage`, but colored acoording to the severity level. |
| 30 | void PrintColoredMessage(const Entry& entry); | 30 | void PrintColoredMessage(const Entry& entry); |
| 31 | |||
| 32 | } | 31 | } |