From 4dc3cf83e47aad28f4599662ec3e3c48ae416474 Mon Sep 17 00:00:00 2001 From: Niram7777 Date: Sat, 25 Jul 2026 14:19:59 +0200 Subject: [PATCH] Log option for flushing (#4755) --- documents/Debugging/Debugging.md | 1 + src/common/logging/log.cpp | 9 +++++++++ src/common/logging/log.h | 1 + src/core/emulator_settings.h | 12 ++++++++---- 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/documents/Debugging/Debugging.md b/documents/Debugging/Debugging.md index 0d9c8880a..a87e7b5e6 100644 --- a/documents/Debugging/Debugging.md +++ b/documents/Debugging/Debugging.md @@ -71,6 +71,7 @@ You can configure the emulator by editing the `config.json` file found in the `u - Examples: - If the log is being spammed with messages coming from Lib.Pad, you can use `Lib.Pad:Critical` to only log critical-level messages. - If you'd like to mute everything, but still want to receive messages from Vulkan rendering: `*:Off Render.Vulkan:Info` (if you want critical at least `*:Critical Render.Vulkan:Info`) + - `flush_level`: Sets the log level for which logs at or above will be flushed. - `skip_duplicate`: Skip same lines with a `Skipped N duplicate messages..` message (`true`/`false`) - By default, the emulator will skip same lines for `maxSkipDuration` milliseconds. - `append`: Append log to the existing file (`true`/`false`) diff --git a/src/common/logging/log.cpp b/src/common/logging/log.cpp index 1f7ef4a16..1fa522915 100644 --- a/src/common/logging/log.cpp +++ b/src/common/logging/log.cpp @@ -218,6 +218,7 @@ void Setup(std::string_view shadps4_filename) { void Switch(std::string_view game_filename) { UpdateSinks(); UpdateLogLevels(EmulatorSettings.GetLogFilter()); + UpdateLogFlushLevel(EmulatorSettings.GetLogFlushLevel()); g_shad_file_sink->_size_limit = EmulatorSettings.GetLogSizeLimit(); g_shad_file_sink->session_file_helper_.open( @@ -317,4 +318,12 @@ void UpdateLogLevels(std::string_view log_filter) { } } } + +void UpdateLogFlushLevel(std::string_view log_flush_level) { + if (!log_flush_level.empty()) { + for (auto& [name, logger] : ALL_LOGGERS) { + logger->flush_on(spdlog::level_from_str(log_flush_level.data())); + } + } +} } // namespace Common::Log diff --git a/src/common/logging/log.h b/src/common/logging/log.h index 287d604a9..fcbdcfb44 100644 --- a/src/common/logging/log.h +++ b/src/common/logging/log.h @@ -40,6 +40,7 @@ void Terminate(); void UpdateSinks(); void UpdateLogLevels(std::string_view log_filter); +void UpdateLogFlushLevel(std::string_view log_flush_level); static constexpr std::array level_string_views{"Trace", "Debug", "Info", "Warning", "Error", "Critical", "Off"}; diff --git a/src/core/emulator_settings.h b/src/core/emulator_settings.h index f6b681ff2..3862d2b95 100644 --- a/src/core/emulator_settings.h +++ b/src/core/emulator_settings.h @@ -245,6 +245,7 @@ struct LogSettings { Setting append{false}; // specific Setting enable{true}; // specific Setting filter{""}; + Setting flush_level{""}; Setting max_skip_duration{5'000}; Setting separate{false}; // specific Setting size_limit{100_MB}; @@ -260,6 +261,7 @@ struct LogSettings { make_override("append", &LogSettings::append), make_override("enable", &LogSettings::enable), make_override("filter", &LogSettings::filter), + make_override("flush_level", &LogSettings::flush_level), make_override("max_skip_duration", &LogSettings::max_skip_duration), make_override("separate", &LogSettings::separate), make_override("size_limit", &LogSettings::size_limit), @@ -272,11 +274,12 @@ struct LogSettings { } }; #ifdef _WIN32 -NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(LogSettings, append, enable, filter, max_skip_duration, separate, - size_limit, skip_duplicate, sync, type) +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(LogSettings, append, enable, filter, flush_level, + max_skip_duration, separate, size_limit, skip_duplicate, sync, + type) #else -NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(LogSettings, append, enable, filter, max_skip_duration, separate, - size_limit, skip_duplicate, sync) +NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(LogSettings, append, enable, filter, flush_level, + max_skip_duration, separate, size_limit, skip_duplicate, sync) #endif // ------------------------------- @@ -653,6 +656,7 @@ public: SETTING_FORWARD_BOOL(m_log, LogAppend, append) SETTING_FORWARD_BOOL(m_log, LogEnable, enable) SETTING_FORWARD(m_log, LogFilter, filter) + SETTING_FORWARD(m_log, LogFlushLevel, flush_level) SETTING_FORWARD(m_log, LogMaxSkipDuration, max_skip_duration) SETTING_FORWARD_BOOL(m_log, LogSeparate, separate) SETTING_FORWARD(m_log, LogSizeLimit, size_limit)