summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/citra/citra.cpp5
-rw-r--r--src/citra/config.cpp2
-rw-r--r--src/citra/default_ini.h2
-rw-r--r--src/citra_qt/config.cpp4
-rw-r--r--src/citra_qt/main.cpp12
-rw-r--r--src/common/CMakeLists.txt2
-rw-r--r--src/common/logging/filter.cpp132
-rw-r--r--src/common/logging/filter.h63
-rw-r--r--src/common/logging/text_formatter.cpp8
-rw-r--r--src/common/logging/text_formatter.h3
-rw-r--r--src/core/settings.h4
11 files changed, 223 insertions, 14 deletions
diff --git a/src/citra/citra.cpp b/src/citra/citra.cpp
index d192428e9..d6e8a4ec7 100644
--- a/src/citra/citra.cpp
+++ b/src/citra/citra.cpp
@@ -7,6 +7,7 @@
7#include "common/common.h" 7#include "common/common.h"
8#include "common/logging/text_formatter.h" 8#include "common/logging/text_formatter.h"
9#include "common/logging/backend.h" 9#include "common/logging/backend.h"
10#include "common/logging/filter.h"
10#include "common/scope_exit.h" 11#include "common/scope_exit.h"
11 12
12#include "core/settings.h" 13#include "core/settings.h"
@@ -20,7 +21,8 @@
20/// Application entry point 21/// Application entry point
21int __cdecl main(int argc, char **argv) { 22int __cdecl main(int argc, char **argv) {
22 std::shared_ptr<Log::Logger> logger = Log::InitGlobalLogger(); 23 std::shared_ptr<Log::Logger> logger = Log::InitGlobalLogger();
23 std::thread logging_thread(Log::TextLoggingLoop, logger); 24 Log::Filter log_filter(Log::Level::Debug);
25 std::thread logging_thread(Log::TextLoggingLoop, logger, &log_filter);
24 SCOPE_EXIT({ 26 SCOPE_EXIT({
25 logger->Close(); 27 logger->Close();
26 logging_thread.join(); 28 logging_thread.join();
@@ -32,6 +34,7 @@ int __cdecl main(int argc, char **argv) {
32 } 34 }
33 35
34 Config config; 36 Config config;
37 log_filter.ParseFilterString(Settings::values.log_filter);
35 38
36 std::string boot_filename = argv[1]; 39 std::string boot_filename = argv[1];
37 EmuWindow_GLFW* emu_window = new EmuWindow_GLFW; 40 EmuWindow_GLFW* emu_window = new EmuWindow_GLFW;
diff --git a/src/citra/config.cpp b/src/citra/config.cpp
index fe0ebe5a8..92764809e 100644
--- a/src/citra/config.cpp
+++ b/src/citra/config.cpp
@@ -64,7 +64,7 @@ void Config::ReadValues() {
64 Settings::values.use_virtual_sd = glfw_config->GetBoolean("Data Storage", "use_virtual_sd", true); 64 Settings::values.use_virtual_sd = glfw_config->GetBoolean("Data Storage", "use_virtual_sd", true);
65 65
66 // Miscellaneous 66 // Miscellaneous
67 Settings::values.enable_log = glfw_config->GetBoolean("Miscellaneous", "enable_log", true); 67 Settings::values.log_filter = glfw_config->Get("Miscellaneous", "log_filter", "*:Info");
68} 68}
69 69
70void Config::Reload() { 70void Config::Reload() {
diff --git a/src/citra/default_ini.h b/src/citra/default_ini.h
index f1f626eed..7cf543e07 100644
--- a/src/citra/default_ini.h
+++ b/src/citra/default_ini.h
@@ -34,7 +34,7 @@ gpu_refresh_rate = ## 60 (default)
34use_virtual_sd = 34use_virtual_sd =
35 35
36[Miscellaneous] 36[Miscellaneous]
37enable_log = 37log_filter = *:Info ## Examples: *:Debug Kernel.SVC:Trace Service.*:Critical
38)"; 38)";
39 39
40} 40}
diff --git a/src/citra_qt/config.cpp b/src/citra_qt/config.cpp
index 3209e5900..0ae6b8b2d 100644
--- a/src/citra_qt/config.cpp
+++ b/src/citra_qt/config.cpp
@@ -52,7 +52,7 @@ void Config::ReadValues() {
52 qt_config->endGroup(); 52 qt_config->endGroup();
53 53
54 qt_config->beginGroup("Miscellaneous"); 54 qt_config->beginGroup("Miscellaneous");
55 Settings::values.enable_log = qt_config->value("enable_log", true).toBool(); 55 Settings::values.log_filter = qt_config->value("log_filter", "*:Info").toString().toStdString();
56 qt_config->endGroup(); 56 qt_config->endGroup();
57} 57}
58 58
@@ -87,7 +87,7 @@ void Config::SaveValues() {
87 qt_config->endGroup(); 87 qt_config->endGroup();
88 88
89 qt_config->beginGroup("Miscellaneous"); 89 qt_config->beginGroup("Miscellaneous");
90 qt_config->setValue("enable_log", Settings::values.enable_log); 90 qt_config->setValue("log_filter", QString::fromStdString(Settings::values.log_filter));
91 qt_config->endGroup(); 91 qt_config->endGroup();
92} 92}
93 93
diff --git a/src/citra_qt/main.cpp b/src/citra_qt/main.cpp
index 5293263cd..817732167 100644
--- a/src/citra_qt/main.cpp
+++ b/src/citra_qt/main.cpp
@@ -11,6 +11,7 @@
11#include "common/logging/text_formatter.h" 11#include "common/logging/text_formatter.h"
12#include "common/logging/log.h" 12#include "common/logging/log.h"
13#include "common/logging/backend.h" 13#include "common/logging/backend.h"
14#include "common/logging/filter.h"
14#include "common/platform.h" 15#include "common/platform.h"
15#include "common/scope_exit.h" 16#include "common/scope_exit.h"
16 17
@@ -42,14 +43,10 @@
42 43
43GMainWindow::GMainWindow() 44GMainWindow::GMainWindow()
44{ 45{
45
46 Pica::g_debug_context = Pica::DebugContext::Construct(); 46 Pica::g_debug_context = Pica::DebugContext::Construct();
47 47
48 Config config; 48 Config config;
49 49
50 if (!Settings::values.enable_log)
51 LogManager::Shutdown();
52
53 ui.setupUi(this); 50 ui.setupUi(this);
54 statusBar()->hide(); 51 statusBar()->hide();
55 52
@@ -277,7 +274,8 @@ void GMainWindow::closeEvent(QCloseEvent* event)
277int __cdecl main(int argc, char* argv[]) 274int __cdecl main(int argc, char* argv[])
278{ 275{
279 std::shared_ptr<Log::Logger> logger = Log::InitGlobalLogger(); 276 std::shared_ptr<Log::Logger> logger = Log::InitGlobalLogger();
280 std::thread logging_thread(Log::TextLoggingLoop, logger); 277 Log::Filter log_filter(Log::Level::Info);
278 std::thread logging_thread(Log::TextLoggingLoop, logger, &log_filter);
281 SCOPE_EXIT({ 279 SCOPE_EXIT({
282 logger->Close(); 280 logger->Close();
283 logging_thread.join(); 281 logging_thread.join();
@@ -285,7 +283,11 @@ int __cdecl main(int argc, char* argv[])
285 283
286 QApplication::setAttribute(Qt::AA_X11InitThreads); 284 QApplication::setAttribute(Qt::AA_X11InitThreads);
287 QApplication app(argc, argv); 285 QApplication app(argc, argv);
286
288 GMainWindow main_window; 287 GMainWindow main_window;
288 // After settings have been loaded by GMainWindow, apply the filter
289 log_filter.ParseFilterString(Settings::values.log_filter);
290
289 main_window.show(); 291 main_window.show();
290 return app.exec(); 292 return app.exec();
291} 293}
diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt
index 7c1d3d1dc..489d2bb7f 100644
--- a/src/common/CMakeLists.txt
+++ b/src/common/CMakeLists.txt
@@ -11,6 +11,7 @@ set(SRCS
11 hash.cpp 11 hash.cpp
12 key_map.cpp 12 key_map.cpp
13 log_manager.cpp 13 log_manager.cpp
14 logging/filter.cpp
14 logging/text_formatter.cpp 15 logging/text_formatter.cpp
15 logging/backend.cpp 16 logging/backend.cpp
16 math_util.cpp 17 math_util.cpp
@@ -49,6 +50,7 @@ set(HEADERS
49 log.h 50 log.h
50 log_manager.h 51 log_manager.h
51 logging/text_formatter.h 52 logging/text_formatter.h
53 logging/filter.h
52 logging/log.h 54 logging/log.h
53 logging/backend.h 55 logging/backend.h
54 math_util.h 56 math_util.h
diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp
new file mode 100644
index 000000000..0cf9b05e7
--- /dev/null
+++ b/src/common/logging/filter.cpp
@@ -0,0 +1,132 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2+
3// Refer to the license.txt file included.
4
5#include <algorithm>
6
7#include "common/logging/filter.h"
8#include "common/logging/backend.h"
9#include "common/string_util.h"
10
11namespace Log {
12
13Filter::Filter(Level default_level) {
14 ResetAll(default_level);
15}
16
17void Filter::ResetAll(Level level) {
18 class_levels.fill(level);
19}
20
21void Filter::SetClassLevel(Class log_class, Level level) {
22 class_levels[static_cast<size_t>(log_class)] = level;
23}
24
25void Filter::SetSubclassesLevel(const ClassInfo& log_class, Level level) {
26 const size_t log_class_i = static_cast<size_t>(log_class.log_class);
27
28 const size_t begin = log_class_i + 1;
29 const size_t end = begin + log_class.num_children;
30 for (size_t i = begin; begin < end; ++i) {
31 class_levels[i] = level;
32 }
33}
34
35void Filter::ParseFilterString(const std::string& filter_str) {
36 auto clause_begin = filter_str.cbegin();
37 while (clause_begin != filter_str.cend()) {
38 auto clause_end = std::find(clause_begin, filter_str.cend(), ' ');
39
40 // If clause isn't empty
41 if (clause_end != clause_begin) {
42 ParseFilterRule(clause_begin, clause_end);
43 }
44
45 if (clause_end != filter_str.cend()) {
46 // Skip over the whitespace
47 ++clause_end;
48 }
49 clause_begin = clause_end;
50 }
51}
52
53template <typename It>
54static Level GetLevelByName(const It begin, const It end) {
55 for (u8 i = 0; i < static_cast<u8>(Level::Count); ++i) {
56 const char* level_name = Logger::GetLevelName(static_cast<Level>(i));
57 if (Common::ComparePartialString(begin, end, level_name)) {
58 return static_cast<Level>(i);
59 }
60 }
61 return Level::Count;
62}
63
64template <typename It>
65static Class GetClassByName(const It begin, const It end) {
66 for (ClassType i = 0; i < static_cast<ClassType>(Class::Count); ++i) {
67 const char* level_name = Logger::GetLogClassName(static_cast<Class>(i));
68 if (Common::ComparePartialString(begin, end, level_name)) {
69 return static_cast<Class>(i);
70 }
71 }
72 return Class::Count;
73}
74
75template <typename InputIt, typename T>
76static InputIt find_last(InputIt begin, const InputIt end, const T& value) {
77 auto match = end;
78 while (begin != end) {
79 auto new_match = std::find(begin, end, value);
80 if (new_match != end) {
81 match = new_match;
82 ++new_match;
83 }
84 begin = new_match;
85 }
86 return match;
87}
88
89bool Filter::ParseFilterRule(const std::string::const_iterator begin,
90 const std::string::const_iterator end) {
91 auto level_separator = std::find(begin, end, ':');
92 if (level_separator == end) {
93 LOG_ERROR(Log, "Invalid log filter. Must specify a log level after `:`: %s",
94 std::string(begin, end).c_str());
95 return false;
96 }
97
98 const Level level = GetLevelByName(level_separator + 1, end);
99 if (level == Level::Count) {
100 LOG_ERROR(Log, "Unknown log level in filter: %s", std::string(begin, end).c_str());
101 return false;
102 }
103
104 if (Common::ComparePartialString(begin, level_separator, "*")) {
105 ResetAll(level);
106 return true;
107 }
108
109 auto class_name_end = find_last(begin, level_separator, '.');
110 if (class_name_end != level_separator &&
111 !Common::ComparePartialString(class_name_end + 1, level_separator, "*")) {
112 class_name_end = level_separator;
113 }
114
115 const Class log_class = GetClassByName(begin, class_name_end);
116 if (log_class == Class::Count) {
117 LOG_ERROR(Log, "Unknown log class in filter: %s", std::string(begin, end).c_str());
118 return false;
119 }
120
121 if (class_name_end == level_separator) {
122 SetClassLevel(log_class, level);
123 }
124 SetSubclassesLevel(log_class, level);
125 return true;
126}
127
128bool Filter::CheckMessage(Class log_class, Level level) const {
129 return static_cast<u8>(level) >= static_cast<u8>(class_levels[static_cast<size_t>(log_class)]);
130}
131
132}
diff --git a/src/common/logging/filter.h b/src/common/logging/filter.h
new file mode 100644
index 000000000..32b14b159
--- /dev/null
+++ b/src/common/logging/filter.h
@@ -0,0 +1,63 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2+
3// Refer to the license.txt file included.
4
5#include <array>
6#include <string>
7
8#include "common/logging/log.h"
9
10namespace Log {
11
12struct ClassInfo;
13
14/**
15 * Implements a log message filter which allows different log classes to have different minimum
16 * severity levels. The filter can be changed at runtime and can be parsed from a string to allow
17 * editing via the interface or loading from a configuration file.
18 */
19class Filter {
20public:
21 /// Initializes the filter with all classes having `default_level` as the minimum level.
22 Filter(Level default_level);
23
24 /// Resets the filter so that all classes have `level` as the minimum displayed level.
25 void ResetAll(Level level);
26 /// Sets the minimum level of `log_class` (and not of its subclasses) to `level`.
27 void SetClassLevel(Class log_class, Level level);
28 /**
29 * Sets the minimum level of all of `log_class` subclasses to `level`. The level of `log_class`
30 * itself is not changed.
31 */
32 void SetSubclassesLevel(const ClassInfo& log_class, Level level);
33
34 /**
35 * Parses a filter string and applies it to this filter.
36 *
37 * A filter string consists of a space-separated list of filter rules, each of the format
38 * `<class>:<level>`. `<class>` is a log class name, with subclasses separated using periods.
39 * A rule for a given class also affects all of its subclasses. `*` wildcards are allowed and
40 * can be used to apply a rule to all classes or to all subclasses of a class without affecting
41 * the parent class. `<level>` a severity level name which will be set as the minimum logging
42 * level of the matched classes. Rules are applied left to right, with each rule overriding
43 * previous ones in the sequence.
44 *
45 * A few examples of filter rules:
46 * - `*:Info` -- Resets the level of all classes to Info.
47 * - `Service:Info` -- Sets the level of Service and all subclasses (Service.FS, Service.APT,
48 * etc.) to Info.
49 * - `Service.*:Debug` -- Sets the level of all Service subclasses to Debug, while leaving the
50 * level of Service unchanged.
51 * - `Service.FS:Trace` -- Sets the level of the Service.FS class to Trace.
52 */
53 void ParseFilterString(const std::string& filter_str);
54 bool ParseFilterRule(const std::string::const_iterator start, const std::string::const_iterator end);
55
56 /// Matches class/level combination against the filter, returning true if it passed.
57 bool CheckMessage(Class log_class, Level level) const;
58
59private:
60 std::array<Level, (size_t)Class::Count> class_levels;
61};
62
63}
diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp
index 88deb150e..3fe435346 100644
--- a/src/common/logging/text_formatter.cpp
+++ b/src/common/logging/text_formatter.cpp
@@ -11,6 +11,7 @@
11#endif 11#endif
12 12
13#include "common/logging/backend.h" 13#include "common/logging/backend.h"
14#include "common/logging/filter.h"
14#include "common/logging/log.h" 15#include "common/logging/log.h"
15#include "common/logging/text_formatter.h" 16#include "common/logging/text_formatter.h"
16 17
@@ -105,7 +106,7 @@ void PrintMessage(const Entry& entry) {
105 fputc('\n', stderr); 106 fputc('\n', stderr);
106} 107}
107 108
108void TextLoggingLoop(std::shared_ptr<Logger> logger) { 109void TextLoggingLoop(std::shared_ptr<Logger> logger, const Filter* filter) {
109 std::array<Entry, 256> entry_buffer; 110 std::array<Entry, 256> entry_buffer;
110 111
111 while (true) { 112 while (true) {
@@ -114,7 +115,10 @@ void TextLoggingLoop(std::shared_ptr<Logger> logger) {
114 break; 115 break;
115 } 116 }
116 for (size_t i = 0; i < num_entries; ++i) { 117 for (size_t i = 0; i < num_entries; ++i) {
117 PrintMessage(entry_buffer[i]); 118 const Entry& entry = entry_buffer[i];
119 if (filter->CheckMessage(entry.log_class, entry.log_level)) {
120 PrintMessage(entry);
121 }
118 } 122 }
119 } 123 }
120} 124}
diff --git a/src/common/logging/text_formatter.h b/src/common/logging/text_formatter.h
index 04164600f..d7e298e28 100644
--- a/src/common/logging/text_formatter.h
+++ b/src/common/logging/text_formatter.h
@@ -11,6 +11,7 @@ namespace Log {
11 11
12class Logger; 12class Logger;
13struct Entry; 13struct Entry;
14class Filter;
14 15
15/** 16/**
16 * Attempts to trim an arbitrary prefix from `path`, leaving only the part starting at `root`. It's 17 * Attempts to trim an arbitrary prefix from `path`, leaving only the part starting at `root`. It's
@@ -33,6 +34,6 @@ void PrintMessage(const Entry& entry);
33 * Logging loop that repeatedly reads messages from the provided logger and prints them to the 34 * Logging loop that repeatedly reads messages from the provided logger and prints them to the
34 * console. It is the baseline barebones log outputter. 35 * console. It is the baseline barebones log outputter.
35 */ 36 */
36void TextLoggingLoop(std::shared_ptr<Logger> logger); 37void TextLoggingLoop(std::shared_ptr<Logger> logger, const Filter* filter);
37 38
38} 39}
diff --git a/src/core/settings.h b/src/core/settings.h
index 7e7a66b89..138ffc615 100644
--- a/src/core/settings.h
+++ b/src/core/settings.h
@@ -4,6 +4,8 @@
4 4
5#pragma once 5#pragma once
6 6
7#include <string>
8
7namespace Settings { 9namespace Settings {
8 10
9struct Values { 11struct Values {
@@ -33,7 +35,7 @@ struct Values {
33 // Data Storage 35 // Data Storage
34 bool use_virtual_sd; 36 bool use_virtual_sd;
35 37
36 bool enable_log; 38 std::string log_filter;
37} extern values; 39} extern values;
38 40
39} 41}