diff options
| author | Léo Lam <leo@leolam.fr> | 2020-10-21 19:11:19 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-21 19:11:19 +0200 |
| commit | 09e87b79f19ce0fb06b236e15ebed414af57558a (patch) | |
| tree | 199f03308f3d349aa0f20bda3d880e75a76b8150 /Source/Core/Common/Logging/LogManager.cpp | |
| parent | f265c412b449f7054468fae6e13a890bb0d3c098 (diff) | |
| parent | 425f2aa013a9051a15b58a722668358a2dae5c70 (diff) | |
Merge pull request #9173 from lioncash/fmtlog
Common/Log: Add basic fmt-capable functions to the interface.
Diffstat (limited to 'Source/Core/Common/Logging/LogManager.cpp')
| -rw-r--r-- | Source/Core/Common/Logging/LogManager.cpp | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/Source/Core/Common/Logging/LogManager.cpp b/Source/Core/Common/Logging/LogManager.cpp index 99ddf83d67..2255fc6f8e 100644 --- a/Source/Core/Common/Logging/LogManager.cpp +++ b/Source/Core/Common/Logging/LogManager.cpp @@ -64,11 +64,34 @@ private: void GenericLog(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, const char* fmt, ...) { + auto* instance = LogManager::GetInstance(); + if (instance == nullptr) + return; + + if (!instance->IsEnabled(type, level)) + return; + va_list args; va_start(args, fmt); - if (LogManager::GetInstance()) - LogManager::GetInstance()->Log(level, type, file, line, fmt, args); + char message[MAX_MSGLEN]; + CharArrayFromFormatV(message, MAX_MSGLEN, fmt, args); va_end(args); + + instance->Log(level, type, file, line, message); +} + +void GenericLogFmtImpl(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, + std::string_view format, const fmt::format_args& args) +{ + auto* instance = LogManager::GetInstance(); + if (instance == nullptr) + return; + + if (!instance->IsEnabled(type, level)) + return; + + const auto message = fmt::vformat(format, args); + instance->Log(level, type, file, line, message.c_str()); } static size_t DeterminePathCutOffPoint() @@ -196,27 +219,26 @@ void LogManager::SaveSettings() } void LogManager::Log(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, - const char* format, va_list args) -{ - return LogWithFullPath(level, type, file + m_path_cutoff_point, line, format, args); -} - -void LogManager::LogWithFullPath(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, - const char* format, va_list args) + const char* message) { if (!IsEnabled(type, level) || !static_cast<bool>(m_listener_ids)) return; - char temp[MAX_MSGLEN]; - CharArrayFromFormatV(temp, MAX_MSGLEN, format, args); + LogWithFullPath(level, type, file + m_path_cutoff_point, line, message); +} +void LogManager::LogWithFullPath(LOG_LEVELS level, LOG_TYPE type, const char* file, int line, + const char* message) +{ const std::string msg = fmt::format("{} {}:{} {}[{}]: {}\n", Common::Timer::GetTimeFormatted(), file, line, - LOG_LEVEL_TO_CHAR[static_cast<int>(level)], GetShortName(type), temp); + LOG_LEVEL_TO_CHAR[static_cast<int>(level)], GetShortName(type), message); - for (auto listener_id : m_listener_ids) + for (const auto listener_id : m_listener_ids) + { if (m_listeners[listener_id]) m_listeners[listener_id]->Log(level, msg.c_str()); + } } LOG_LEVELS LogManager::GetLogLevel() const |
