diff options
| author | 2018-04-02 21:19:20 -0400 | |
|---|---|---|
| committer | 2018-04-02 21:19:20 -0400 | |
| commit | c2e0820ac2c0b51c0b14af608f4225eec8712f5e (patch) | |
| tree | 0a40b6f36c98402748b881fb43986f32d16ffbd8 /src/common/logging/backend.cpp | |
| parent | Merge pull request #267 from N00byKing/patch-1 (diff) | |
| parent | Remove dependency chrono (diff) | |
| download | yuzu-c2e0820ac2c0b51c0b14af608f4225eec8712f5e.tar.gz yuzu-c2e0820ac2c0b51c0b14af608f4225eec8712f5e.tar.xz yuzu-c2e0820ac2c0b51c0b14af608f4225eec8712f5e.zip | |
Merge pull request #262 from daniellimws/fmtlib-macros
Logging: Add fmtlib-based macros
Diffstat (limited to 'src/common/logging/backend.cpp')
| -rw-r--r-- | src/common/logging/backend.cpp | 36 |
1 files changed, 22 insertions, 14 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index a763f4abf..3db654913 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 | ||
| 15 | namespace Log { | 16 | namespace Log { |
| 16 | 17 | ||
| @@ -106,25 +107,20 @@ const char* GetLevelName(Level log_level) { | |||
| 106 | } | 107 | } |
| 107 | 108 | ||
| 108 | Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, | 109 | Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, |
| 109 | const char* function, const char* format, va_list args) { | 110 | const char* function, std::string message) { |
| 110 | using std::chrono::duration_cast; | 111 | using std::chrono::duration_cast; |
| 111 | using std::chrono::steady_clock; | 112 | using std::chrono::steady_clock; |
| 112 | 113 | ||
| 113 | static steady_clock::time_point time_origin = steady_clock::now(); | 114 | static steady_clock::time_point time_origin = steady_clock::now(); |
| 114 | 115 | ||
| 115 | std::array<char, 4 * 1024> formatting_buffer; | ||
| 116 | |||
| 117 | Entry entry; | 116 | Entry entry; |
| 118 | entry.timestamp = duration_cast<std::chrono::microseconds>(steady_clock::now() - time_origin); | 117 | entry.timestamp = duration_cast<std::chrono::microseconds>(steady_clock::now() - time_origin); |
| 119 | entry.log_class = log_class; | 118 | entry.log_class = log_class; |
| 120 | entry.log_level = log_level; | 119 | entry.log_level = log_level; |
| 121 | 120 | entry.filename = Common::TrimSourcePath(filename); | |
| 122 | snprintf(formatting_buffer.data(), formatting_buffer.size(), "%s:%s:%u", filename, function, | 121 | entry.line_num = line_nr; |
| 123 | line_nr); | 122 | entry.function = function; |
| 124 | entry.location = std::string(formatting_buffer.data()); | 123 | entry.message = std::move(message); |
| 125 | |||
| 126 | vsnprintf(formatting_buffer.data(), formatting_buffer.size(), format, args); | ||
| 127 | entry.message = std::string(formatting_buffer.data()); | ||
| 128 | 124 | ||
| 129 | return entry; | 125 | return entry; |
| 130 | } | 126 | } |
| @@ -135,15 +131,27 @@ void SetFilter(Filter* new_filter) { | |||
| 135 | filter = new_filter; | 131 | filter = new_filter; |
| 136 | } | 132 | } |
| 137 | 133 | ||
| 138 | void LogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_nr, | 134 | void LogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num, |
| 139 | const char* function, const char* format, ...) { | 135 | const char* function, const char* format, ...) { |
| 140 | if (filter != nullptr && !filter->CheckMessage(log_class, log_level)) | 136 | if (filter && !filter->CheckMessage(log_class, log_level)) |
| 141 | return; | 137 | return; |
| 142 | 138 | std::array<char, 4 * 1024> formatting_buffer; | |
| 143 | va_list args; | 139 | va_list args; |
| 144 | va_start(args, format); | 140 | va_start(args, format); |
| 145 | Entry entry = CreateEntry(log_class, log_level, filename, line_nr, function, format, args); | 141 | vsnprintf(formatting_buffer.data(), formatting_buffer.size(), format, args); |
| 146 | va_end(args); | 142 | va_end(args); |
| 143 | Entry entry = CreateEntry(log_class, log_level, filename, line_num, function, | ||
| 144 | std::string(formatting_buffer.data())); | ||
| 145 | |||
| 146 | PrintColoredMessage(entry); | ||
| 147 | } | ||
| 148 | |||
| 149 | void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num, | ||
| 150 | const char* function, const char* format, const fmt::ArgList& args) { | ||
| 151 | if (filter && !filter->CheckMessage(log_class, log_level)) | ||
| 152 | return; | ||
| 153 | Entry entry = | ||
| 154 | CreateEntry(log_class, log_level, filename, line_num, function, fmt::format(format, args)); | ||
| 147 | 155 | ||
| 148 | PrintColoredMessage(entry); | 156 | PrintColoredMessage(entry); |
| 149 | } | 157 | } |