summaryrefslogtreecommitdiff
path: root/src/common/logging/backend.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/logging/backend.cpp')
-rw-r--r--src/common/logging/backend.cpp139
1 files changed, 71 insertions, 68 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 @@
16namespace Log { 16namespace 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...
72const char* GetLogClassName(Class log_class) { 72const 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
84const char* GetLevelName(Level log_level) { 88const 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
99Entry CreateEntry(Class log_class, Level log_level, 105Entry 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
129void LogMessage(Class log_class, Level log_level, 135void 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}