diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2026-11-04 18:26:31 -0600 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2026-11-08 13:08:09 -0600 |
| commit | 5c3b7f75e1a5e40a8e9761863d7022b3003c252f (patch) | |
| tree | b8b56232a57e11c43f532a0bd468c65bfe3e85f3 /Source | |
| parent | 122d1534c0f736615f30b9530bbe4c81aefae7e5 (diff) | |
Common/Logging/LogManager: Clean up "path cutoff point" calculation.
Diffstat (limited to 'Source')
| -rw-r--r-- | Source/Core/Common/Logging/LogManager.cpp | 29 | ||||
| -rw-r--r-- | Source/Core/Common/Logging/LogManager.h | 1 |
2 files changed, 10 insertions, 20 deletions
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 <algorithm> #include <atomic> #include <chrono> -#include <cstring> #include <fstream> #include <memory> #include <mutex> @@ -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<bool>{{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<bool>(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<LogContainer, LAST_LOG_TYPE> m_log{}; std::array<std::unique_ptr<LogListener>, LogListener::NUMBER_OF_LISTENERS> m_listeners{}; BitSet32 m_listener_ids; - size_t m_path_cutoff_point = 0; }; } // namespace Common::Log |
