mirror of
https://github.com/stenzek/duckstation.git
synced 2025-12-28 05:24:19 +00:00
Log: Fix empty output with only main window logs enabled
Some checks failed
GameDB Lint / gamedb-lint (push) Has been cancelled
Automated Builds / 💻 Windows (push) Has been cancelled
Automated Builds / 🐧 Linux AppImage (push) Has been cancelled
Automated Builds / 🐧 Linux Cross-Compiled AppImage (push) Has been cancelled
Automated Builds / 🍎 MacOS (push) Has been cancelled
Automated Builds / 📤 Create Release (push) Has been cancelled
Some checks failed
GameDB Lint / gamedb-lint (push) Has been cancelled
Automated Builds / 💻 Windows (push) Has been cancelled
Automated Builds / 🐧 Linux AppImage (push) Has been cancelled
Automated Builds / 🐧 Linux Cross-Compiled AppImage (push) Has been cancelled
Automated Builds / 🍎 MacOS (push) Has been cancelled
Automated Builds / 📤 Create Release (push) Has been cancelled
This commit is contained in:
parent
52bd6e7495
commit
4810b1c7da
@ -42,6 +42,7 @@ static void RegisterCallback(CallbackFunctionType callbackFunction, void* pUserP
|
|||||||
const std::unique_lock<std::mutex>& lock);
|
const std::unique_lock<std::mutex>& lock);
|
||||||
static void UnregisterCallback(CallbackFunctionType callbackFunction, void* pUserParam,
|
static void UnregisterCallback(CallbackFunctionType callbackFunction, void* pUserParam,
|
||||||
const std::unique_lock<std::mutex>& lock);
|
const std::unique_lock<std::mutex>& lock);
|
||||||
|
static void UpdateEffectiveLevel();
|
||||||
|
|
||||||
static bool FilterTest(Channel channel, Level level);
|
static bool FilterTest(Channel channel, Level level);
|
||||||
static void ExecuteCallbacks(MessageCategory cat, const char* functionName, std::string_view message);
|
static void ExecuteCallbacks(MessageCategory cat, const char* functionName, std::string_view message);
|
||||||
@ -75,7 +76,8 @@ namespace {
|
|||||||
|
|
||||||
struct State
|
struct State
|
||||||
{
|
{
|
||||||
Level log_level = Level::Trace;
|
Level effective_log_level = Level::None;
|
||||||
|
Level requested_log_level = Level::Trace;
|
||||||
ChannelBitSet log_channels_enabled = ChannelBitSet().set();
|
ChannelBitSet log_channels_enabled = ChannelBitSet().set();
|
||||||
|
|
||||||
std::vector<RegisteredCallback> callbacks;
|
std::vector<RegisteredCallback> callbacks;
|
||||||
@ -118,6 +120,7 @@ void Log::RegisterCallback(CallbackFunctionType callbackFunction, void* pUserPar
|
|||||||
Callback.Parameter = pUserParam;
|
Callback.Parameter = pUserParam;
|
||||||
|
|
||||||
s_state.callbacks.push_back(std::move(Callback));
|
s_state.callbacks.push_back(std::move(Callback));
|
||||||
|
UpdateEffectiveLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log::UnregisterCallback(CallbackFunctionType callbackFunction, void* pUserParam)
|
void Log::UnregisterCallback(CallbackFunctionType callbackFunction, void* pUserParam)
|
||||||
@ -134,11 +137,17 @@ void Log::UnregisterCallback(CallbackFunctionType callbackFunction, void* pUserP
|
|||||||
if (iter->Function == callbackFunction && iter->Parameter == pUserParam)
|
if (iter->Function == callbackFunction && iter->Parameter == pUserParam)
|
||||||
{
|
{
|
||||||
s_state.callbacks.erase(iter);
|
s_state.callbacks.erase(iter);
|
||||||
|
UpdateEffectiveLevel();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Log::UpdateEffectiveLevel()
|
||||||
|
{
|
||||||
|
s_state.effective_log_level = s_state.callbacks.empty() ? Level::None : s_state.requested_log_level;
|
||||||
|
}
|
||||||
|
|
||||||
const std::array<const char*, static_cast<size_t>(Log::Channel::MaxCount)>& Log::GetChannelNames()
|
const std::array<const char*, static_cast<size_t>(Log::Channel::MaxCount)>& Log::GetChannelNames()
|
||||||
{
|
{
|
||||||
return s_log_channel_names;
|
return s_log_channel_names;
|
||||||
@ -530,7 +539,7 @@ void Log::SetFileOutputParams(bool enabled, const char* filename, bool timestamp
|
|||||||
|
|
||||||
Log::Level Log::GetLogLevel()
|
Log::Level Log::GetLogLevel()
|
||||||
{
|
{
|
||||||
return s_state.log_level;
|
return s_state.effective_log_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Log::IsLogVisible(Level level, Channel channel)
|
bool Log::IsLogVisible(Level level, Channel channel)
|
||||||
@ -542,7 +551,8 @@ void Log::SetLogLevel(Level level)
|
|||||||
{
|
{
|
||||||
std::unique_lock lock(s_state.callbacks_mutex);
|
std::unique_lock lock(s_state.callbacks_mutex);
|
||||||
DebugAssert(level < Level::MaxCount);
|
DebugAssert(level < Level::MaxCount);
|
||||||
s_state.log_level = level;
|
s_state.requested_log_level = level;
|
||||||
|
UpdateEffectiveLevel();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log::SetLogChannelEnabled(Channel channel, bool enabled)
|
void Log::SetLogChannelEnabled(Channel channel, bool enabled)
|
||||||
@ -559,7 +569,7 @@ const char* Log::GetChannelName(Channel channel)
|
|||||||
|
|
||||||
ALWAYS_INLINE_RELEASE bool Log::FilterTest(Channel channel, Level level)
|
ALWAYS_INLINE_RELEASE bool Log::FilterTest(Channel channel, Level level)
|
||||||
{
|
{
|
||||||
return (level <= s_state.log_level && s_state.log_channels_enabled[static_cast<size_t>(channel)]);
|
return (level <= s_state.effective_log_level && s_state.log_channels_enabled[static_cast<size_t>(channel)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Log::Write(MessageCategory cat, std::string_view message)
|
void Log::Write(MessageCategory cat, std::string_view message)
|
||||||
|
|||||||
@ -1272,13 +1272,10 @@ void Settings::UpdateLogConfig(const SettingsInterface& si)
|
|||||||
const bool log_timestamps = si.GetBoolValue("Logging", "LogTimestamps", true);
|
const bool log_timestamps = si.GetBoolValue("Logging", "LogTimestamps", true);
|
||||||
const bool log_to_console = si.GetBoolValue("Logging", "LogToConsole", false);
|
const bool log_to_console = si.GetBoolValue("Logging", "LogToConsole", false);
|
||||||
const bool log_to_debug = si.GetBoolValue("Logging", "LogToDebug", false);
|
const bool log_to_debug = si.GetBoolValue("Logging", "LogToDebug", false);
|
||||||
const bool log_to_window = si.GetBoolValue("Logging", "LogToWindow", false);
|
|
||||||
const bool log_to_file = si.GetBoolValue("Logging", "LogToFile", false);
|
const bool log_to_file = si.GetBoolValue("Logging", "LogToFile", false);
|
||||||
const bool log_file_timestamps = si.GetBoolValue("Logging", "LogFileTimestamps", false);
|
const bool log_file_timestamps = si.GetBoolValue("Logging", "LogFileTimestamps", false);
|
||||||
|
|
||||||
const bool any_logs_enabled = (log_to_console || log_to_debug || log_to_window || log_to_file);
|
Log::SetLogLevel(log_level);
|
||||||
Log::SetLogLevel(any_logs_enabled ? log_level : Log::Level::None);
|
|
||||||
|
|
||||||
Log::SetConsoleOutputParams(log_to_console, log_timestamps);
|
Log::SetConsoleOutputParams(log_to_console, log_timestamps);
|
||||||
Log::SetDebugOutputParams(log_to_debug);
|
Log::SetDebugOutputParams(log_to_debug);
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user