diff options
| author | 2018-03-22 18:21:29 +0800 | |
|---|---|---|
| committer | 2018-03-22 18:21:29 +0800 | |
| commit | 3b558eebee54fa4bc9d1a7bb428d4bd33e1b817e (patch) | |
| tree | c6e2a53e92f1ef289edf26212a0f82fb0c97e718 /src/common/logging/backend.cpp | |
| parent | Merge pull request #215 from N00byKing/umapsharedmmry (diff) | |
| download | yuzu-3b558eebee54fa4bc9d1a7bb428d4bd33e1b817e.tar.gz yuzu-3b558eebee54fa4bc9d1a7bb428d4bd33e1b817e.tar.xz yuzu-3b558eebee54fa4bc9d1a7bb428d4bd33e1b817e.zip | |
Logging: Create logging macros based on fmtlib
Add a new set of logging macros based on fmtlib
Similar but not exactly the same as https://github.com/citra-emu/citra/pull/3533
Citra currently uses a different version of fmt, which does not support FMT_VARIADIC so
make_args is used instead. On the other hand, yuzu uses fmt 4.1.0 which doesn't have make_args yet
so FMT_VARIADIC is used.
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 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 | ||
| 15 | namespace Log { | 16 | namespace Log { |
| 16 | 17 | ||
| @@ -102,25 +103,20 @@ const char* GetLevelName(Level log_level) { | |||
| 102 | } | 103 | } |
| 103 | 104 | ||
| 104 | Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, | 105 | Entry 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 | ||
| 134 | void LogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_nr, | 130 | void 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 | |||
| 145 | void 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 | } |