diff options
| author | 2016-09-21 11:29:48 -0700 | |
|---|---|---|
| committer | 2016-09-21 11:29:48 -0700 | |
| commit | d5d2ca8058a0f1c00ab7ca9fe2c058ba47546c0a (patch) | |
| tree | 8a22ca73ff838f3f0090b29a548ae81087fc90ed /src/common/logging/backend.cpp | |
| parent | README: Specify master branch for Travis CI badge (diff) | |
| parent | Fix Travis clang-format check (diff) | |
| download | yuzu-d5d2ca8058a0f1c00ab7ca9fe2c058ba47546c0a.tar.gz yuzu-d5d2ca8058a0f1c00ab7ca9fe2c058ba47546c0a.tar.xz yuzu-d5d2ca8058a0f1c00ab7ca9fe2c058ba47546c0a.zip | |
Merge pull request #2086 from linkmauve/clang-format
Add clang-format as part of our {commit,travis}-time checks
Diffstat (limited to 'src/common/logging/backend.cpp')
| -rw-r--r-- | src/common/logging/backend.cpp | 140 |
1 files changed, 71 insertions, 69 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 0b2fabec9..9a13a9e90 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp | |||
| @@ -5,7 +5,6 @@ | |||
| 5 | #include <algorithm> | 5 | #include <algorithm> |
| 6 | #include <array> | 6 | #include <array> |
| 7 | #include <cstdio> | 7 | #include <cstdio> |
| 8 | |||
| 9 | #include "common/assert.h" | 8 | #include "common/assert.h" |
| 10 | #include "common/common_funcs.h" // snprintf compatibility define | 9 | #include "common/common_funcs.h" // snprintf compatibility define |
| 11 | #include "common/logging/backend.h" | 10 | #include "common/logging/backend.h" |
| @@ -16,73 +15,79 @@ | |||
| 16 | namespace Log { | 15 | namespace Log { |
| 17 | 16 | ||
| 18 | /// Macro listing all log classes. Code should define CLS and SUB as desired before invoking this. | 17 | /// Macro listing all log classes. Code should define CLS and SUB as desired before invoking this. |
| 19 | #define ALL_LOG_CLASSES() \ | 18 | #define ALL_LOG_CLASSES() \ |
| 20 | CLS(Log) \ | 19 | CLS(Log) \ |
| 21 | CLS(Common) \ | 20 | CLS(Common) \ |
| 22 | SUB(Common, Filesystem) \ | 21 | SUB(Common, Filesystem) \ |
| 23 | SUB(Common, Memory) \ | 22 | SUB(Common, Memory) \ |
| 24 | CLS(Core) \ | 23 | CLS(Core) \ |
| 25 | SUB(Core, ARM11) \ | 24 | SUB(Core, ARM11) \ |
| 26 | SUB(Core, Timing) \ | 25 | SUB(Core, Timing) \ |
| 27 | CLS(Config) \ | 26 | CLS(Config) \ |
| 28 | CLS(Debug) \ | 27 | CLS(Debug) \ |
| 29 | SUB(Debug, Emulated) \ | 28 | SUB(Debug, Emulated) \ |
| 30 | SUB(Debug, GPU) \ | 29 | SUB(Debug, GPU) \ |
| 31 | SUB(Debug, Breakpoint) \ | 30 | SUB(Debug, Breakpoint) \ |
| 32 | SUB(Debug, GDBStub) \ | 31 | SUB(Debug, GDBStub) \ |
| 33 | CLS(Kernel) \ | 32 | CLS(Kernel) \ |
| 34 | SUB(Kernel, SVC) \ | 33 | SUB(Kernel, SVC) \ |
| 35 | CLS(Service) \ | 34 | CLS(Service) \ |
| 36 | SUB(Service, SRV) \ | 35 | SUB(Service, SRV) \ |
| 37 | SUB(Service, FRD) \ | 36 | SUB(Service, FRD) \ |
| 38 | SUB(Service, FS) \ | 37 | SUB(Service, FS) \ |
| 39 | SUB(Service, ERR) \ | 38 | SUB(Service, ERR) \ |
| 40 | SUB(Service, APT) \ | 39 | SUB(Service, APT) \ |
| 41 | SUB(Service, GSP) \ | 40 | SUB(Service, GSP) \ |
| 42 | SUB(Service, AC) \ | 41 | SUB(Service, AC) \ |
| 43 | SUB(Service, AM) \ | 42 | SUB(Service, AM) \ |
| 44 | SUB(Service, PTM) \ | 43 | SUB(Service, PTM) \ |
| 45 | SUB(Service, LDR) \ | 44 | SUB(Service, LDR) \ |
| 46 | SUB(Service, NDM) \ | 45 | SUB(Service, NDM) \ |
| 47 | SUB(Service, NIM) \ | 46 | SUB(Service, NIM) \ |
| 48 | SUB(Service, NWM) \ | 47 | SUB(Service, NWM) \ |
| 49 | SUB(Service, CAM) \ | 48 | SUB(Service, CAM) \ |
| 50 | SUB(Service, CECD) \ | 49 | SUB(Service, CECD) \ |
| 51 | SUB(Service, CFG) \ | 50 | SUB(Service, CFG) \ |
| 52 | SUB(Service, DSP) \ | 51 | SUB(Service, DSP) \ |
| 53 | SUB(Service, DLP) \ | 52 | SUB(Service, DLP) \ |
| 54 | SUB(Service, HID) \ | 53 | SUB(Service, HID) \ |
| 55 | SUB(Service, SOC) \ | 54 | SUB(Service, SOC) \ |
| 56 | SUB(Service, IR) \ | 55 | SUB(Service, IR) \ |
| 57 | SUB(Service, Y2R) \ | 56 | SUB(Service, Y2R) \ |
| 58 | CLS(HW) \ | 57 | CLS(HW) \ |
| 59 | SUB(HW, Memory) \ | 58 | SUB(HW, Memory) \ |
| 60 | SUB(HW, LCD) \ | 59 | SUB(HW, LCD) \ |
| 61 | SUB(HW, GPU) \ | 60 | SUB(HW, GPU) \ |
| 62 | CLS(Frontend) \ | 61 | CLS(Frontend) \ |
| 63 | CLS(Render) \ | 62 | CLS(Render) \ |
| 64 | SUB(Render, Software) \ | 63 | SUB(Render, Software) \ |
| 65 | SUB(Render, OpenGL) \ | 64 | SUB(Render, OpenGL) \ |
| 66 | CLS(Audio) \ | 65 | CLS(Audio) \ |
| 67 | SUB(Audio, DSP) \ | 66 | SUB(Audio, DSP) \ |
| 68 | SUB(Audio, Sink) \ | 67 | SUB(Audio, Sink) \ |
| 69 | CLS(Loader) | 68 | CLS(Loader) |
| 70 | 69 | ||
| 71 | // GetClassName is a macro defined by Windows.h, grrr... | 70 | // GetClassName is a macro defined by Windows.h, grrr... |
| 72 | const char* GetLogClassName(Class log_class) { | 71 | const char* GetLogClassName(Class log_class) { |
| 73 | switch (log_class) { | 72 | switch (log_class) { |
| 74 | #define CLS(x) case Class::x: return #x; | 73 | #define CLS(x) \ |
| 75 | #define SUB(x, y) case Class::x##_##y: return #x "." #y; | 74 | case Class::x: \ |
| 75 | return #x; | ||
| 76 | #define SUB(x, y) \ | ||
| 77 | case Class::x##_##y: \ | ||
| 78 | return #x "." #y; | ||
| 76 | ALL_LOG_CLASSES() | 79 | ALL_LOG_CLASSES() |
| 77 | #undef CLS | 80 | #undef CLS |
| 78 | #undef SUB | 81 | #undef SUB |
| 79 | case Class::Count: | 82 | case Class::Count: |
| 80 | UNREACHABLE(); | 83 | UNREACHABLE(); |
| 81 | } | 84 | } |
| 82 | } | 85 | } |
| 83 | 86 | ||
| 84 | const char* GetLevelName(Level log_level) { | 87 | const char* GetLevelName(Level log_level) { |
| 85 | #define LVL(x) case Level::x: return #x | 88 | #define LVL(x) \ |
| 89 | case Level::x: \ | ||
| 90 | return #x | ||
| 86 | switch (log_level) { | 91 | switch (log_level) { |
| 87 | LVL(Trace); | 92 | LVL(Trace); |
| 88 | LVL(Debug); | 93 | LVL(Debug); |
| @@ -90,15 +95,14 @@ const char* GetLevelName(Level log_level) { | |||
| 90 | LVL(Warning); | 95 | LVL(Warning); |
| 91 | LVL(Error); | 96 | LVL(Error); |
| 92 | LVL(Critical); | 97 | LVL(Critical); |
| 93 | case Level::Count: | 98 | case Level::Count: |
| 94 | UNREACHABLE(); | 99 | UNREACHABLE(); |
| 95 | } | 100 | } |
| 96 | #undef LVL | 101 | #undef LVL |
| 97 | } | 102 | } |
| 98 | 103 | ||
| 99 | Entry CreateEntry(Class log_class, Level log_level, | 104 | 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, | 105 | const char* function, const char* format, va_list args) { |
| 101 | const char* format, va_list args) { | ||
| 102 | using std::chrono::steady_clock; | 106 | using std::chrono::steady_clock; |
| 103 | using std::chrono::duration_cast; | 107 | using std::chrono::duration_cast; |
| 104 | 108 | ||
| @@ -111,7 +115,8 @@ Entry CreateEntry(Class log_class, Level log_level, | |||
| 111 | entry.log_class = log_class; | 115 | entry.log_class = log_class; |
| 112 | entry.log_level = log_level; | 116 | entry.log_level = log_level; |
| 113 | 117 | ||
| 114 | snprintf(formatting_buffer.data(), formatting_buffer.size(), "%s:%s:%u", filename, function, line_nr); | 118 | snprintf(formatting_buffer.data(), formatting_buffer.size(), "%s:%s:%u", filename, function, |
| 119 | line_nr); | ||
| 115 | entry.location = std::string(formatting_buffer.data()); | 120 | entry.location = std::string(formatting_buffer.data()); |
| 116 | 121 | ||
| 117 | vsnprintf(formatting_buffer.data(), formatting_buffer.size(), format, args); | 122 | vsnprintf(formatting_buffer.data(), formatting_buffer.size(), format, args); |
| @@ -126,19 +131,16 @@ void SetFilter(Filter* new_filter) { | |||
| 126 | filter = new_filter; | 131 | filter = new_filter; |
| 127 | } | 132 | } |
| 128 | 133 | ||
| 129 | void LogMessage(Class log_class, Level log_level, | 134 | 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, | 135 | const char* function, const char* format, ...) { |
| 131 | const char* format, ...) { | ||
| 132 | if (filter != nullptr && !filter->CheckMessage(log_class, log_level)) | 136 | if (filter != nullptr && !filter->CheckMessage(log_class, log_level)) |
| 133 | return; | 137 | return; |
| 134 | 138 | ||
| 135 | va_list args; | 139 | va_list args; |
| 136 | va_start(args, format); | 140 | va_start(args, format); |
| 137 | Entry entry = CreateEntry(log_class, log_level, | 141 | Entry entry = CreateEntry(log_class, log_level, filename, line_nr, function, format, args); |
| 138 | filename, line_nr, function, format, args); | ||
| 139 | va_end(args); | 142 | va_end(args); |
| 140 | 143 | ||
| 141 | PrintColoredMessage(entry); | 144 | PrintColoredMessage(entry); |
| 142 | } | 145 | } |
| 143 | |||
| 144 | } | 146 | } |