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/text_formatter.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/text_formatter.cpp')
| -rw-r--r-- | src/common/logging/text_formatter.cpp | 41 |
1 files changed, 10 insertions, 31 deletions
diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp index e7e46c76b..8583916a8 100644 --- a/src/common/logging/text_formatter.cpp +++ b/src/common/logging/text_formatter.cpp | |||
| @@ -18,50 +18,29 @@ | |||
| 18 | 18 | ||
| 19 | namespace Log { | 19 | namespace Log { |
| 20 | 20 | ||
| 21 | // TODO(bunnei): This should be moved to a generic path manipulation library | 21 | std::string FormatLogMessage(const Entry& entry) { |
| 22 | const char* TrimSourcePath(const char* path, const char* root) { | ||
| 23 | const char* p = path; | ||
| 24 | |||
| 25 | while (*p != '\0') { | ||
| 26 | const char* next_slash = p; | ||
| 27 | while (*next_slash != '\0' && *next_slash != '/' && *next_slash != '\\') { | ||
| 28 | ++next_slash; | ||
| 29 | } | ||
| 30 | |||
| 31 | bool is_src = Common::ComparePartialString(p, next_slash, root); | ||
| 32 | p = next_slash; | ||
| 33 | |||
| 34 | if (*p != '\0') { | ||
| 35 | ++p; | ||
| 36 | } | ||
| 37 | if (is_src) { | ||
| 38 | path = p; | ||
| 39 | } | ||
| 40 | } | ||
| 41 | return path; | ||
| 42 | } | ||
| 43 | |||
| 44 | void FormatLogMessage(const Entry& entry, char* out_text, size_t text_len) { | ||
| 45 | unsigned int time_seconds = static_cast<unsigned int>(entry.timestamp.count() / 1000000); | 22 | unsigned int time_seconds = static_cast<unsigned int>(entry.timestamp.count() / 1000000); |
| 46 | unsigned int time_fractional = static_cast<unsigned int>(entry.timestamp.count() % 1000000); | 23 | unsigned int time_fractional = static_cast<unsigned int>(entry.timestamp.count() % 1000000); |
| 47 | 24 | ||
| 48 | const char* class_name = GetLogClassName(entry.log_class); | 25 | const char* class_name = GetLogClassName(entry.log_class); |
| 49 | const char* level_name = GetLevelName(entry.log_level); | 26 | const char* level_name = GetLevelName(entry.log_level); |
| 50 | 27 | ||
| 51 | snprintf(out_text, text_len, "[%4u.%06u] %s <%s> %s: %s", time_seconds, time_fractional, | 28 | return fmt::format("[{:4d}.{:06d}] {} <{}> {}:{}:{}: {}", time_seconds, time_fractional, |
| 52 | class_name, level_name, TrimSourcePath(entry.location.c_str()), entry.message.c_str()); | 29 | class_name, level_name, entry.filename, entry.function, entry.line_num, |
| 30 | entry.message); | ||
| 53 | } | 31 | } |
| 54 | 32 | ||
| 55 | void PrintMessage(const Entry& entry) { | 33 | void PrintMessage(const Entry& entry) { |
| 56 | std::array<char, 4 * 1024> format_buffer; | 34 | auto str = FormatLogMessage(entry) + '\n'; |
| 57 | FormatLogMessage(entry, format_buffer.data(), format_buffer.size()); | 35 | fputs(str.c_str(), stderr); |
| 58 | fputs(format_buffer.data(), stderr); | ||
| 59 | fputc('\n', stderr); | ||
| 60 | } | 36 | } |
| 61 | 37 | ||
| 62 | void PrintColoredMessage(const Entry& entry) { | 38 | void PrintColoredMessage(const Entry& entry) { |
| 63 | #ifdef _WIN32 | 39 | #ifdef _WIN32 |
| 64 | static HANDLE console_handle = GetStdHandle(STD_ERROR_HANDLE); | 40 | HANDLE console_handle = GetStdHandle(STD_ERROR_HANDLE); |
| 41 | if (console_handle == INVALID_HANDLE_VALUE) { | ||
| 42 | return; | ||
| 43 | } | ||
| 65 | 44 | ||
| 66 | CONSOLE_SCREEN_BUFFER_INFO original_info = {0}; | 45 | CONSOLE_SCREEN_BUFFER_INFO original_info = {0}; |
| 67 | GetConsoleScreenBufferInfo(console_handle, &original_info); | 46 | GetConsoleScreenBufferInfo(console_handle, &original_info); |