From 8d16971a6fcd3534c9dd34d625c151d2a5ce3ed9 Mon Sep 17 00:00:00 2001 From: Shawn Hoffman Date: Sun, 17 Jul 2022 19:46:34 -0700 Subject: LogManager: use own timestamp function --- Source/Core/Common/Logging/LogManager.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) (limited to 'Source/Core/Common/Logging/LogManager.cpp') 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 +#include #include #include #include @@ -11,6 +12,7 @@ #include #include +#include #include #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(now); + const auto now_ms = std::chrono::floor(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(level)], GetShortName(type), message); for (const auto listener_id : m_listener_ids) -- cgit v1.2.3