From 122d1534c0f736615f30b9530bbe4c81aefae7e5 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Wed, 4 Nov 2026 17:49:13 -0600 Subject: Common/Logging: Make LogManager deleted functions public to eliminate a clang-tidy warning. --- Source/Core/Common/Logging/LogManager.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Source/Core') diff --git a/Source/Core/Common/Logging/LogManager.h b/Source/Core/Common/Logging/LogManager.h index 8253c5e118..8bddd39abb 100644 --- a/Source/Core/Common/Logging/LogManager.h +++ b/Source/Core/Common/Logging/LogManager.h @@ -78,14 +78,14 @@ public: void SaveSettings(); -private: - LogManager(); - LogManager(const LogManager&) = delete; LogManager& operator=(const LogManager&) = delete; LogManager(LogManager&&) = delete; LogManager& operator=(LogManager&&) = delete; +private: + LogManager(); + static std::string GetTimestamp(); void SetEffectiveLogLevel(); -- cgit v1.2.3 From 5c3b7f75e1a5e40a8e9761863d7022b3003c252f Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Wed, 4 Nov 2026 18:26:31 -0600 Subject: Common/Logging/LogManager: Clean up "path cutoff point" calculation. --- Source/Core/Common/Logging/LogManager.cpp | 29 ++++++++++------------------- Source/Core/Common/Logging/LogManager.h | 1 - 2 files changed, 10 insertions(+), 20 deletions(-) (limited to 'Source/Core') diff --git a/Source/Core/Common/Logging/LogManager.cpp b/Source/Core/Common/Logging/LogManager.cpp index 89ae089a44..5a586623cb 100644 --- a/Source/Core/Common/Logging/LogManager.cpp +++ b/Source/Core/Common/Logging/LogManager.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include #include #include @@ -19,7 +18,6 @@ #include "Common/FileUtil.h" #include "Common/Logging/ConsoleListener.h" #include "Common/Logging/Log.h" -#include "Common/StringUtil.h" namespace Common::Log { @@ -74,22 +72,17 @@ void GenericLogFmtImpl(LogLevel level, LogType type, const char* file, int line, instance->Log(level, type, file, line, message.c_str()); } -static size_t DeterminePathCutOffPoint() +static consteval size_t GetPathCutOffPoint() { - constexpr const char* pattern = "/source/core/"; -#ifdef _WIN32 - constexpr const char* pattern2 = "\\source\\core\\"; + constexpr std::string_view pattern = +#if defined(_WIN32) + "Common\\Logging\\LogManager.cpp"; +#else + "Common/Logging/LogManager.cpp"; #endif - std::string path = __FILE__; - Common::ToLower(&path); - size_t pos = path.find(pattern); -#ifdef _WIN32 - if (pos == std::string::npos) - pos = path.find(pattern2); -#endif - if (pos != std::string::npos) - return pos + strlen(pattern); - return 0; + constexpr std::string_view filename = __FILE__; + static_assert(filename.ends_with(pattern)); + return filename.length() - pattern.length(); } LogManager::LogManager() @@ -170,8 +163,6 @@ LogManager::LogManager() Config::Info{{Config::System::Logger, "Logs", container.m_short_name}, false}); } - m_path_cutoff_point = DeterminePathCutOffPoint(); - m_config_changed_callback_id = Config::AddConfigChangedCallback([this]() { SetEffectiveLogLevel(); }); } @@ -205,7 +196,7 @@ void LogManager::Log(LogLevel level, LogType type, const char* file, int line, c if (!IsEnabled(type, level) || !static_cast(m_listener_ids)) return; - LogWithFullPath(level, type, file + m_path_cutoff_point, line, message); + LogWithFullPath(level, type, file + GetPathCutOffPoint(), line, message); } std::string LogManager::GetTimestamp() diff --git a/Source/Core/Common/Logging/LogManager.h b/Source/Core/Common/Logging/LogManager.h index 8bddd39abb..624cd1e697 100644 --- a/Source/Core/Common/Logging/LogManager.h +++ b/Source/Core/Common/Logging/LogManager.h @@ -94,6 +94,5 @@ private: EnumMap m_log{}; std::array, LogListener::NUMBER_OF_LISTENERS> m_listeners{}; BitSet32 m_listener_ids; - size_t m_path_cutoff_point = 0; }; } // namespace Common::Log -- cgit v1.2.3 From d02fc5f4bb1733a0cfd45ee00b4a8e3ff2a53ca3 Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Wed, 4 Nov 2026 18:58:44 -0600 Subject: Common/Logging/LogManager: Add IsListenerEnabled function to avoid string formatting when log types are enabled but all listeners are disabled. Also eliminate redundant IsEnabled(type, level) check. --- Source/Core/Common/Logging/LogManager.cpp | 5 +---- Source/Core/Common/Logging/LogManager.h | 1 + 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'Source/Core') diff --git a/Source/Core/Common/Logging/LogManager.cpp b/Source/Core/Common/Logging/LogManager.cpp index 5a586623cb..ae3ea6a66c 100644 --- a/Source/Core/Common/Logging/LogManager.cpp +++ b/Source/Core/Common/Logging/LogManager.cpp @@ -65,7 +65,7 @@ void GenericLogFmtImpl(LogLevel level, LogType type, const char* file, int line, if (instance == nullptr) return; - if (!instance->IsEnabled(type, level)) + if (!instance->IsEnabled(type, level) || !instance->IsAnyListenerEnabled()) return; const auto message = fmt::vformat(format, args); @@ -193,9 +193,6 @@ void LogManager::SaveSettings() void LogManager::Log(LogLevel level, LogType type, const char* file, int line, const char* message) { - if (!IsEnabled(type, level) || !static_cast(m_listener_ids)) - return; - LogWithFullPath(level, type, file + GetPathCutOffPoint(), line, message); } diff --git a/Source/Core/Common/Logging/LogManager.h b/Source/Core/Common/Logging/LogManager.h index 624cd1e697..7e145b0da1 100644 --- a/Source/Core/Common/Logging/LogManager.h +++ b/Source/Core/Common/Logging/LogManager.h @@ -75,6 +75,7 @@ public: void RegisterListener(LogListener::LISTENER id, std::unique_ptr listener); void EnableListener(LogListener::LISTENER id, bool enable); bool IsListenerEnabled(LogListener::LISTENER id) const; + bool IsAnyListenerEnabled() const { return static_cast(m_listener_ids); } void SaveSettings(); -- cgit v1.2.3 From 055767399abab0eff6f55acbf480e54fcd83f6bd Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Wed, 4 Nov 2026 18:59:40 -0600 Subject: Common/Logging/LogManager: Pass string_view instead of char* to give fmt string length awareness without having to perform strlen calls. --- Source/Core/AudioCommon/CubebUtils.cpp | 2 +- Source/Core/Common/Logging/LogManager.cpp | 7 ++++--- Source/Core/Common/Logging/LogManager.h | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) (limited to 'Source/Core') diff --git a/Source/Core/AudioCommon/CubebUtils.cpp b/Source/Core/AudioCommon/CubebUtils.cpp index 0be4fdeb81..67a2c3a824 100644 --- a/Source/Core/AudioCommon/CubebUtils.cpp +++ b/Source/Core/AudioCommon/CubebUtils.cpp @@ -39,7 +39,7 @@ static void LogCallback(const char* format, ...) const std::string message = StringFromFormatV(adapted_format.c_str(), args); va_end(args); - instance->LogWithFullPath(log_level, log_type, filename, lineno, message.c_str()); + instance->LogWithFullPath(log_level, log_type, filename, lineno, message); } static void DestroyContext(cubeb* ctx) diff --git a/Source/Core/Common/Logging/LogManager.cpp b/Source/Core/Common/Logging/LogManager.cpp index ae3ea6a66c..0bc51bfa5b 100644 --- a/Source/Core/Common/Logging/LogManager.cpp +++ b/Source/Core/Common/Logging/LogManager.cpp @@ -69,7 +69,7 @@ void GenericLogFmtImpl(LogLevel level, LogType type, const char* file, int line, return; const auto message = fmt::vformat(format, args); - instance->Log(level, type, file, line, message.c_str()); + instance->Log(level, type, file, line, message); } static consteval size_t GetPathCutOffPoint() @@ -191,7 +191,8 @@ void LogManager::SaveSettings() Config::Save(); } -void LogManager::Log(LogLevel level, LogType type, const char* file, int line, const char* message) +void LogManager::Log(LogLevel level, LogType type, const char* file, int line, + std::string_view message) { LogWithFullPath(level, type, file + GetPathCutOffPoint(), line, message); } @@ -209,7 +210,7 @@ std::string LogManager::GetTimestamp() } void LogManager::LogWithFullPath(LogLevel level, LogType type, const char* file, int line, - const char* message) + std::string_view message) { const std::string msg = fmt::format("{} {}:{} {}[{}]: {}\n", GetTimestamp(), file, line, diff --git a/Source/Core/Common/Logging/LogManager.h b/Source/Core/Common/Logging/LogManager.h index 7e145b0da1..060488a98f 100644 --- a/Source/Core/Common/Logging/LogManager.h +++ b/Source/Core/Common/Logging/LogManager.h @@ -56,9 +56,9 @@ public: static void Init(); static void Shutdown(); - void Log(LogLevel level, LogType type, const char* file, int line, const char* message); + void Log(LogLevel level, LogType type, const char* file, int line, std::string_view message); void LogWithFullPath(LogLevel level, LogType type, const char* file, int line, - const char* message); + std::string_view message); // Use this function instead of LOGGER_VERBOSITY to determine which logs should be printed. LogLevel GetEffectiveLogLevel() const; -- cgit v1.2.3 From 43c95acd01968c33c8cc2a02c27e5d6d872022ef Mon Sep 17 00:00:00 2001 From: Jordan Woyak Date: Wed, 4 Nov 2026 19:00:59 -0600 Subject: Common/Logging/LogManager: Combine GetTimestamp functionality into LogWithFullPath to eliminate one std::string construction. --- Source/Core/Common/Logging/LogManager.cpp | 10 +++------- Source/Core/Common/Logging/LogManager.h | 1 - 2 files changed, 3 insertions(+), 8 deletions(-) (limited to 'Source/Core') diff --git a/Source/Core/Common/Logging/LogManager.cpp b/Source/Core/Common/Logging/LogManager.cpp index 0bc51bfa5b..f35826793f 100644 --- a/Source/Core/Common/Logging/LogManager.cpp +++ b/Source/Core/Common/Logging/LogManager.cpp @@ -197,7 +197,8 @@ void LogManager::Log(LogLevel level, LogType type, const char* file, int line, LogWithFullPath(level, type, file + GetPathCutOffPoint(), line, message); } -std::string LogManager::GetTimestamp() +void LogManager::LogWithFullPath(LogLevel level, LogType type, const char* file, int line, + std::string_view message) { // NOTE: the Qt LogWidget hardcodes the expected length of the timestamp portion of the log line, // so ensure they stay in sync @@ -206,14 +207,9 @@ std::string LogManager::GetTimestamp() 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, - std::string_view message) -{ const std::string msg = - fmt::format("{} {}:{} {}[{}]: {}\n", GetTimestamp(), file, line, + fmt::format("{:%M:%S}:{:03} {}:{} {}[{}]: {}\n", now_s, (now_ms - now_s).count(), file, line, LOG_LEVEL_TO_CHAR[static_cast(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 060488a98f..bd388e6d74 100644 --- a/Source/Core/Common/Logging/LogManager.h +++ b/Source/Core/Common/Logging/LogManager.h @@ -87,7 +87,6 @@ public: private: LogManager(); - static std::string GetTimestamp(); void SetEffectiveLogLevel(); std::atomic m_effective_level; -- cgit v1.2.3