diff options
author | bunnei <bunneidev@gmail.com> | 2018-04-03 03:19:20 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-03 03:19:20 +0200 |
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 yuzu-c2e0820ac2c0b51c0b14af608f4225eec8712f5e.tar.gz yuzu-c2e0820ac2c0b51c0b14af608f4225eec8712f5e.tar.bz2 yuzu-c2e0820ac2c0b51c0b14af608f4225eec8712f5e.tar.lz yuzu-c2e0820ac2c0b51c0b14af608f4225eec8712f5e.tar.xz yuzu-c2e0820ac2c0b51c0b14af608f4225eec8712f5e.tar.zst yuzu-c2e0820ac2c0b51c0b14af608f4225eec8712f5e.zip |
Diffstat (limited to '')
-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 @@ #include "common/logging/filter.h" #include "common/logging/log.h" #include "common/logging/text_formatter.h" +#include "common/string_util.h" namespace Log { @@ -106,25 +107,20 @@ const char* GetLevelName(Level log_level) { } Entry CreateEntry(Class log_class, Level log_level, const char* filename, unsigned int line_nr, - const char* function, const char* format, va_list args) { + const char* function, std::string message) { using std::chrono::duration_cast; using std::chrono::steady_clock; static steady_clock::time_point time_origin = steady_clock::now(); - std::array<char, 4 * 1024> formatting_buffer; - Entry entry; entry.timestamp = duration_cast<std::chrono::microseconds>(steady_clock::now() - time_origin); entry.log_class = log_class; entry.log_level = log_level; - - snprintf(formatting_buffer.data(), formatting_buffer.size(), "%s:%s:%u", filename, function, - line_nr); - entry.location = std::string(formatting_buffer.data()); - - vsnprintf(formatting_buffer.data(), formatting_buffer.size(), format, args); - entry.message = std::string(formatting_buffer.data()); + entry.filename = Common::TrimSourcePath(filename); + entry.line_num = line_nr; + entry.function = function; + entry.message = std::move(message); return entry; } @@ -135,15 +131,27 @@ void SetFilter(Filter* new_filter) { filter = new_filter; } -void LogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_nr, +void LogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num, const char* function, const char* format, ...) { - if (filter != nullptr && !filter->CheckMessage(log_class, log_level)) + if (filter && !filter->CheckMessage(log_class, log_level)) return; - + std::array<char, 4 * 1024> formatting_buffer; va_list args; va_start(args, format); - Entry entry = CreateEntry(log_class, log_level, filename, line_nr, function, format, args); + vsnprintf(formatting_buffer.data(), formatting_buffer.size(), format, args); va_end(args); + Entry entry = CreateEntry(log_class, log_level, filename, line_num, function, + std::string(formatting_buffer.data())); + + PrintColoredMessage(entry); +} + +void FmtLogMessage(Class log_class, Level log_level, const char* filename, unsigned int line_num, + const char* function, const char* format, const fmt::ArgList& args) { + if (filter && !filter->CheckMessage(log_class, log_level)) + return; + Entry entry = + CreateEntry(log_class, log_level, filename, line_num, function, fmt::format(format, args)); PrintColoredMessage(entry); } |