summaryrefslogtreecommitdiff
path: root/src/common/logging/backend.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/common/logging/backend.cpp36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 7f3ae1a4e..22afa1d66 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -11,6 +11,7 @@
11#include "common/logging/filter.h" 11#include "common/logging/filter.h"
12#include "common/logging/log.h" 12#include "common/logging/log.h"
13#include "common/logging/text_formatter.h" 13#include "common/logging/text_formatter.h"
14#include "common/string_util.h"
14 15
15namespace Log { 16namespace Log {
16 17
@@ -102,25 +103,20 @@ const char* GetLevelName(Level log_level) {
102} 103}
103 104
104Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, 105Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr,
105 const char* function, const char* format, va_list args) { 106 const char* function, std::string message) {
106 using std::chrono::duration_cast; 107 using std::chrono::duration_cast;
107 using std::chrono::steady_clock; 108 using std::chrono::steady_clock;
108 109
109 static steady_clock::time_point time_origin = steady_clock::now(); 110 static steady_clock::time_point time_origin = steady_clock::now();
110 111
111 std::array<char, 4 * 1024> formatting_buffer;
112
113 Entry entry; 112 Entry entry;
114 entry.timestamp = duration_cast<std::chrono::microseconds>(steady_clock::now() - time_origin); 113 entry.timestamp = duration_cast<std::chrono::microseconds>(steady_clock::now() - time_origin);
115 entry.log_class = log_class; 114 entry.log_class = log_class;
116 entry.log_level = log_level; 115 entry.log_level = log_level;
117 116 entry.filename = Common::TrimSourcePath(filename);
118 snprintf(formatting_buffer.data(), formatting_buffer.size(), "%s:%s:%u", filename, function, 117 entry.line_num = line_nr;
119 line_nr); 118 entry.function = function;
120 entry.location = std::string(formatting_buffer.data()); 119 entry.message = std::move(message);
121
122 vsnprintf(formatting_buffer.data(), formatting_buffer.size(), format, args);
123 entry.message = std::string(formatting_buffer.data());
124 120
125 return entry; 121 return entry;
126} 122}
@@ -131,15 +127,27 @@ void SetFilter(Filter* new_filter) {
131 filter = new_filter; 127 filter = new_filter;
132} 128}
133 129
134void LogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_nr, 130void LogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num,
135 const char* function, const char* format, ...) { 131 const char* function, const char* format, ...) {
136 if (filter != nullptr && !filter->CheckMessage(log_class, log_level)) 132 if (filter && !filter->CheckMessage(log_class, log_level))
137 return; 133 return;
138 134 std::array<char, 4 * 1024> formatting_buffer;
139 va_list args; 135 va_list args;
140 va_start(args, format); 136 va_start(args, format);
141 Entry entry = CreateEntry(log_class, log_level, filename, line_nr, function, format, args); 137 vsnprintf(formatting_buffer.data(), formatting_buffer.size(), format, args);
142 va_end(args); 138 va_end(args);
139 Entry entry = CreateEntry(log_class, log_level, filename, line_num, function,
140 std::string(formatting_buffer.data()));
141
142 PrintColoredMessage(entry);
143}
144
145void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num,
146 const char* function, const char* format, const fmt::ArgList& args) {
147 if (filter && !filter->CheckMessage(log_class, log_level))
148 return;
149 Entry entry =
150 CreateEntry(log_class, log_level, filename, line_num, function, fmt::format(format, args));
143 151
144 PrintColoredMessage(entry); 152 PrintColoredMessage(entry);
145} 153}