Skip to content
This repository has been archived by the owner on Oct 29, 2024. It is now read-only.

Commit

Permalink
Add log regex filter
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloMK7 committed Mar 5, 2024
1 parent bf0127d commit ea1d63f
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/android/app/src/main/jni/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 2 additions & 0 deletions src/citra/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
2 changes: 2 additions & 0 deletions src/citra_qt/configuration/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/citra_qt/configuration/configure_debug.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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();
Expand Down
14 changes: 14 additions & 0 deletions src/citra_qt/configuration/configure_debug.ui
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,20 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="label_3">
<property name="text">
<string>Regex Log Filter</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="log_regex_filter_edit"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
Expand Down
28 changes: 26 additions & 2 deletions src/common/logging/backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// Refer to the license.txt file included.

#include <chrono>
#include <boost/regex.hpp>

#include <fmt/format.h>

Expand Down Expand Up @@ -234,6 +235,19 @@ class Impl {
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);
}
Expand All @@ -243,8 +257,13 @@ class Impl {
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:
Expand Down Expand Up @@ -406,6 +425,7 @@ class Impl {
static inline std::unique_ptr<Impl, decltype(&Deleter)> instance{nullptr, Deleter};

Filter filter;
boost::regex regex_filter;
DebuggerBackend debugger_backend{};
ColorConsoleBackend color_console_backend{};
FileBackend file_backend;
Expand Down Expand Up @@ -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);
}
Expand Down
6 changes: 6 additions & 0 deletions src/common/logging/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions src/common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ struct Values {

// Miscellaneous
Setting<std::string> log_filter{"*:Info", "log_filter"};
Setting<std::string> log_regex_filter{"", "log_regex_filter"};

// Video Dumping
std::string output_format;
Expand Down

0 comments on commit ea1d63f

Please sign in to comment.