From f112d975b9d0cd0b2787872bbc4ccebe9acbcd4d Mon Sep 17 00:00:00 2001 From: PabloMK7 Date: Tue, 5 Mar 2024 14:51:58 +0100 Subject: [PATCH] Add log regex filter (#9) --- src/android/app/src/main/jni/config.cpp | 2 ++ src/citra/config.cpp | 2 ++ src/citra_qt/configuration/config.cpp | 2 ++ .../configuration/configure_debug.cpp | 4 +++ src/citra_qt/configuration/configure_debug.ui | 14 ++++++++++ src/common/logging/backend.cpp | 28 +++++++++++++++++-- src/common/logging/backend.h | 6 ++++ src/common/settings.h | 1 + 8 files changed, 57 insertions(+), 2 deletions(-) diff --git a/src/android/app/src/main/jni/config.cpp b/src/android/app/src/main/jni/config.cpp index f2210f225..9f86861c8 100644 --- a/src/android/app/src/main/jni/config.cpp +++ b/src/android/app/src/main/jni/config.cpp @@ -244,12 +244,14 @@ void Config::ReadValues() { // Miscellaneous ReadSetting("Miscellaneous", Settings::values.log_filter); + ReadSetting("Miscellaneous", Settings::values.log_regex_filter); // Apply the log_filter setting as the logger has already been initialized // and doesn't pick up the filter on its own. Common::Log::Filter filter; filter.ParseFilterString(Settings::values.log_filter.GetValue()); Common::Log::SetGlobalFilter(filter); + Common::Log::SetRegexFilter(Settings::values.log_regex_filter.GetValue()); // Debugging Settings::values.record_frame_times = diff --git a/src/citra/config.cpp b/src/citra/config.cpp index baf5bbded..32e7ae1ef 100644 --- a/src/citra/config.cpp +++ b/src/citra/config.cpp @@ -306,12 +306,14 @@ void Config::ReadValues() { // Miscellaneous ReadSetting("Miscellaneous", Settings::values.log_filter); + ReadSetting("Miscellaneous", Settings::values.log_regex_filter); // Apply the log_filter setting as the logger has already been initialized // and doesn't pick up the filter on its own. Common::Log::Filter filter; filter.ParseFilterString(Settings::values.log_filter.GetValue()); Common::Log::SetGlobalFilter(filter); + Common::Log::SetRegexFilter(Settings::values.log_regex_filter.GetValue()); // Debugging Settings::values.record_frame_times = diff --git a/src/citra_qt/configuration/config.cpp b/src/citra_qt/configuration/config.cpp index 54c8c4f4b..f3714a447 100644 --- a/src/citra_qt/configuration/config.cpp +++ b/src/citra_qt/configuration/config.cpp @@ -536,6 +536,7 @@ void Config::ReadMiscellaneousValues() { qt_config->beginGroup(QStringLiteral("Miscellaneous")); ReadBasicSetting(Settings::values.log_filter); + ReadBasicSetting(Settings::values.log_regex_filter); ReadBasicSetting(Settings::values.enable_gamemode); qt_config->endGroup(); @@ -1068,6 +1069,7 @@ void Config::SaveMiscellaneousValues() { qt_config->beginGroup(QStringLiteral("Miscellaneous")); WriteBasicSetting(Settings::values.log_filter); + WriteBasicSetting(Settings::values.log_regex_filter); WriteBasicSetting(Settings::values.enable_gamemode); qt_config->endGroup(); diff --git a/src/citra_qt/configuration/configure_debug.cpp b/src/citra_qt/configuration/configure_debug.cpp index 2386e2049..b843c3bc3 100644 --- a/src/citra_qt/configuration/configure_debug.cpp +++ b/src/citra_qt/configuration/configure_debug.cpp @@ -97,6 +97,8 @@ void ConfigureDebug::SetConfiguration() { ui->toggle_console->setEnabled(!is_powered_on); ui->toggle_console->setChecked(UISettings::values.show_console.GetValue()); ui->log_filter_edit->setText(QString::fromStdString(Settings::values.log_filter.GetValue())); + ui->log_regex_filter_edit->setText( + QString::fromStdString(Settings::values.log_regex_filter.GetValue())); ui->toggle_cpu_jit->setChecked(Settings::values.use_cpu_jit.GetValue()); ui->delay_start_for_lle_modules->setChecked( Settings::values.delay_start_for_lle_modules.GetValue()); @@ -126,10 +128,12 @@ void ConfigureDebug::ApplyConfiguration() { Settings::values.gdbstub_port = ui->gdbport_spinbox->value(); UISettings::values.show_console = ui->toggle_console->isChecked(); Settings::values.log_filter = ui->log_filter_edit->text().toStdString(); + Settings::values.log_regex_filter = ui->log_regex_filter_edit->text().toStdString(); Debugger::ToggleConsole(); Common::Log::Filter filter; filter.ParseFilterString(Settings::values.log_filter.GetValue()); Common::Log::SetGlobalFilter(filter); + Common::Log::SetRegexFilter(Settings::values.log_regex_filter.GetValue()); Settings::values.use_cpu_jit = ui->toggle_cpu_jit->isChecked(); Settings::values.delay_start_for_lle_modules = ui->delay_start_for_lle_modules->isChecked(); Settings::values.renderer_debug = ui->toggle_renderer_debug->isChecked(); diff --git a/src/citra_qt/configuration/configure_debug.ui b/src/citra_qt/configuration/configure_debug.ui index faf8b9ee0..eacf85be9 100644 --- a/src/citra_qt/configuration/configure_debug.ui +++ b/src/citra_qt/configuration/configure_debug.ui @@ -85,6 +85,20 @@ + + + + + + Regex Log Filter + + + + + + + + diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index b33462472..9f8f82c99 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #include +#include #include @@ -234,6 +235,19 @@ public: filter = f; } + bool SetRegexFilter(const std::string& regex) { + if (regex.empty()) { + regex_filter = boost::regex(); + return true; + } + regex_filter = boost::regex(regex, boost::regex_constants::no_except); + if (regex_filter.status() != 0) { + regex_filter = boost::regex(); + return false; + } + return true; + } + void SetColorConsoleBackendEnabled(bool enabled) { color_console_backend.SetEnabled(enabled); } @@ -243,8 +257,13 @@ public: if (!filter.CheckMessage(log_class, log_level)) { return; } - message_queue.EmplaceWait( - CreateEntry(log_class, log_level, filename, line_num, function, std::move(message))); + Entry new_entry = + CreateEntry(log_class, log_level, filename, line_num, function, std::move(message)); + if (!regex_filter.empty() && + !boost::regex_search(FormatLogMessage(new_entry), regex_filter)) { + return; + } + message_queue.EmplaceWait(new_entry); } private: @@ -406,6 +425,7 @@ private: static inline std::unique_ptr instance{nullptr, Deleter}; Filter filter; + boost::regex regex_filter; DebuggerBackend debugger_backend{}; ColorConsoleBackend color_console_backend{}; FileBackend file_backend; @@ -446,6 +466,10 @@ void SetGlobalFilter(const Filter& filter) { Impl::Instance().SetGlobalFilter(filter); } +bool SetRegexFilter(const std::string& regex) { + return Impl::Instance().SetRegexFilter(regex); +} + void SetColorConsoleBackendEnabled(bool enabled) { Impl::Instance().SetColorConsoleBackendEnabled(enabled); } diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index 8b664af36..e16a129b1 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h @@ -26,5 +26,11 @@ void DisableLoggingInTests(); */ void SetGlobalFilter(const Filter& filter); +/** + * Only allow messages that match the specified regex. The regex is matched against the final log + * text. + */ +bool SetRegexFilter(const std::string& regex); + void SetColorConsoleBackendEnabled(bool enabled); } // namespace Common::Log diff --git a/src/common/settings.h b/src/common/settings.h index e463ba4d7..64bba90ee 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -542,6 +542,7 @@ struct Values { // Miscellaneous Setting log_filter{"*:Info", "log_filter"}; + Setting log_regex_filter{"", "log_regex_filter"}; // Video Dumping std::string output_format;