diff options
| author | Shawn Hoffman <godisgovernment@gmail.com> | 2022-07-17 19:46:34 -0700 |
|---|---|---|
| committer | Shawn Hoffman <godisgovernment@gmail.com> | 2022-08-02 22:24:05 -0700 |
| commit | 8d16971a6fcd3534c9dd34d625c151d2a5ce3ed9 (patch) | |
| tree | 10f38fb35189e0c3c4b93dbeb29347e9c6b285b1 /Source/Core | |
| parent | 7d2d5d914bf3cacbecbb0bf8a642b616744aad54 (diff) | |
LogManager: use own timestamp function
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/Common/Logging/LogManager.cpp | 17 | ||||
| -rw-r--r-- | Source/Core/Common/Logging/LogManager.h | 2 |
2 files changed, 17 insertions, 2 deletions
diff --git a/Source/Core/Common/Logging/LogManager.cpp b/Source/Core/Common/Logging/LogManager.cpp index 2fa86a11b2..80e7db895e 100644 --- a/Source/Core/Common/Logging/LogManager.cpp +++ b/Source/Core/Common/Logging/LogManager.cpp @@ -4,6 +4,7 @@ #include "Common/Logging/LogManager.h" #include <algorithm> +#include <chrono> #include <cstdarg> #include <cstring> #include <locale> @@ -11,6 +12,7 @@ #include <ostream> #include <string> +#include <fmt/chrono.h> #include <fmt/format.h> #include "Common/CommonPaths.h" @@ -19,7 +21,6 @@ #include "Common/Logging/ConsoleListener.h" #include "Common/Logging/Log.h" #include "Common/StringUtil.h" -#include "Common/Timer.h" namespace Common::Log { @@ -204,11 +205,23 @@ void LogManager::Log(LogLevel level, LogType type, const char* file, int line, c LogWithFullPath(level, type, file + m_path_cutoff_point, line, message); } +std::string LogManager::GetTimestamp() +{ + // NOTE: the Qt LogWidget hardcodes the expected length of the timestamp portion of the log line, + // so ensure they stay in sync + + // We want milliseconds *and not hours*, so can't directly use STL formatters + const auto now = std::chrono::system_clock::now(); + const auto now_s = std::chrono::floor<std::chrono::seconds>(now); + const auto now_ms = std::chrono::floor<std::chrono::milliseconds>(now); + return fmt::format("{:%M:%S}:{:03}", now_s, (now_ms - now_s).count()); +} + void LogManager::LogWithFullPath(LogLevel level, LogType type, const char* file, int line, const char* message) { const std::string msg = - fmt::format("{} {}:{} {}[{}]: {}\n", Common::Timer::GetTimeFormatted(), file, line, + fmt::format("{} {}:{} {}[{}]: {}\n", GetTimestamp(), file, line, LOG_LEVEL_TO_CHAR[static_cast<int>(level)], GetShortName(type), message); for (const auto listener_id : m_listener_ids) diff --git a/Source/Core/Common/Logging/LogManager.h b/Source/Core/Common/Logging/LogManager.h index 070edd82b4..093d31e01d 100644 --- a/Source/Core/Common/Logging/LogManager.h +++ b/Source/Core/Common/Logging/LogManager.h @@ -75,6 +75,8 @@ private: LogManager(LogManager&&) = delete; LogManager& operator=(LogManager&&) = delete; + static std::string GetTimestamp(); + LogLevel m_level; EnumMap<LogContainer, LAST_LOG_TYPE> m_log{}; std::array<LogListener*, LogListener::NUMBER_OF_LISTENERS> m_listeners{}; |
