diff options
| author | Dentomologist <dentomologist@gmail.com> | 2025-09-11 16:38:07 -0700 |
|---|---|---|
| committer | Dentomologist <dentomologist@gmail.com> | 2025-09-19 13:25:42 -0700 |
| commit | 2d48043b61613dc293a48e3ed863e36ffdf6643e (patch) | |
| tree | a0c6936afca68650e5a7e2915aad413640951e66 /Source/Core/Common/Logging/LogManager.cpp | |
| parent | 79614956f39fc1f6d47ff3fcf6484ef19f4e1ae4 (diff) | |
Logging: Don't overwrite LDEBUG verbosity in Release builds
Preserve the configured logging verbosity unless the user actually
changes it, rather than capping it to LINFO on release builds.
Rename LogManager::m_level to m_effective_level and distinguish between
the config and effective level in various function/variable names.
Make m_effective_level atomic to prevent data races when setting the
effective log level from the config changed callback.
Diffstat (limited to 'Source/Core/Common/Logging/LogManager.cpp')
| -rw-r--r-- | Source/Core/Common/Logging/LogManager.cpp | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/Source/Core/Common/Logging/LogManager.cpp b/Source/Core/Common/Logging/LogManager.cpp index d0117ad07f..a1302a8171 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 <atomic> #include <chrono> #include <cstdarg> #include <cstring> @@ -156,9 +157,7 @@ LogManager::LogManager() RegisterListener(LogListener::CONSOLE_LISTENER, std::make_unique<ConsoleListener>()); // Set up log listeners - LogLevel verbosity = Config::Get(LOGGER_VERBOSITY); - - SetLogLevel(verbosity); + SetEffectiveLogLevel(); EnableListener(LogListener::FILE_LISTENER, Config::Get(LOGGER_WRITE_TO_FILE)); EnableListener(LogListener::CONSOLE_LISTENER, Config::Get(LOGGER_WRITE_TO_CONSOLE)); EnableListener(LogListener::LOG_WINDOW_LISTENER, Config::Get(LOGGER_WRITE_TO_WINDOW)); @@ -170,9 +169,15 @@ LogManager::LogManager() } m_path_cutoff_point = DeterminePathCutOffPoint(); + + m_config_changed_callback_id = + Config::AddConfigChangedCallback([this]() { SetEffectiveLogLevel(); }); } -LogManager::~LogManager() = default; +LogManager::~LogManager() +{ + Config::RemoveConfigChangedCallback(m_config_changed_callback_id); +} void LogManager::SaveSettings() { @@ -183,7 +188,6 @@ void LogManager::SaveSettings() IsListenerEnabled(LogListener::CONSOLE_LISTENER)); Config::SetBaseOrCurrent(LOGGER_WRITE_TO_WINDOW, IsListenerEnabled(LogListener::LOG_WINDOW_LISTENER)); - Config::SetBaseOrCurrent(LOGGER_VERBOSITY, GetLogLevel()); for (const auto& container : m_log) { @@ -228,14 +232,22 @@ void LogManager::LogWithFullPath(LogLevel level, LogType type, const char* file, } } -LogLevel LogManager::GetLogLevel() const +LogLevel LogManager::GetEffectiveLogLevel() const +{ + return m_effective_level.load(std::memory_order_relaxed); +} + +void LogManager::SetConfigLogLevel(const LogLevel level) { - return m_level; + Config::SetBaseOrCurrent(LOGGER_VERBOSITY, level); + SetEffectiveLogLevel(); } -void LogManager::SetLogLevel(LogLevel level) +void LogManager::SetEffectiveLogLevel() { - m_level = std::clamp(level, LogLevel::LNOTICE, MAX_LOGLEVEL); + const LogLevel clamped_level = + std::clamp(Config::Get(LOGGER_VERBOSITY), LogLevel::LNOTICE, MAX_EFFECTIVE_LOGLEVEL); + m_effective_level.store(clamped_level, std::memory_order_relaxed); } void LogManager::SetEnable(LogType type, bool enable) @@ -245,7 +257,7 @@ void LogManager::SetEnable(LogType type, bool enable) bool LogManager::IsEnabled(LogType type, LogLevel level) const { - return m_log[type].m_enable && GetLogLevel() >= level; + return m_log[type].m_enable && GetEffectiveLogLevel() >= level; } std::vector<LogManager::LogContainer> LogManager::GetLogTypes() |
