summaryrefslogtreecommitdiff
path: root/src/common/logging
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/logging')
-rw-r--r--src/common/logging/backend.cpp42
-rw-r--r--src/common/logging/filter.cpp2
-rw-r--r--src/common/logging/text_formatter.cpp35
-rw-r--r--src/common/logging/text_formatter.h2
-rw-r--r--src/common/logging/types.h202
5 files changed, 173 insertions, 110 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 2a3bded40..6e8e8eb36 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -28,7 +28,7 @@
#ifdef _WIN32
#include "common/string_util.h"
#endif
-#include "common/threadsafe_queue.h"
+#include "common/bounded_threadsafe_queue.h"
namespace Common::Log {
@@ -155,6 +155,26 @@ public:
void EnableForStacktrace() override {}
};
+#ifdef ANDROID
+/**
+ * Backend that writes to the Android logcat
+ */
+class LogcatBackend : public Backend {
+public:
+ explicit LogcatBackend() = default;
+
+ ~LogcatBackend() override = default;
+
+ void Write(const Entry& entry) override {
+ PrintMessageToLogcat(entry);
+ }
+
+ void Flush() override {}
+
+ void EnableForStacktrace() override {}
+};
+#endif
+
bool initialization_in_progress_suppress_logging = true;
/**
@@ -204,11 +224,11 @@ public:
void PushEntry(Class log_class, Level log_level, const char* filename, unsigned int line_num,
const char* function, std::string&& message) {
- if (!filter.CheckMessage(log_class, log_level))
+ if (!filter.CheckMessage(log_class, log_level)) {
return;
- const Entry& entry =
- CreateEntry(log_class, log_level, filename, line_num, function, std::move(message));
- message_queue.Push(entry);
+ }
+ message_queue.EmplaceWait(
+ CreateEntry(log_class, log_level, filename, line_num, function, std::move(message)));
}
private:
@@ -225,7 +245,7 @@ private:
ForEachBackend([&entry](Backend& backend) { backend.Write(entry); });
};
while (!stop_token.stop_requested()) {
- entry = message_queue.PopWait(stop_token);
+ message_queue.PopWait(entry, stop_token);
if (entry.filename != nullptr) {
write_logs();
}
@@ -233,7 +253,7 @@ private:
// Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a
// case where a system is repeatedly spamming logs even on close.
int max_logs_to_write = filter.IsDebug() ? INT_MAX : 100;
- while (max_logs_to_write-- && message_queue.Pop(entry)) {
+ while (max_logs_to_write-- && message_queue.TryPop(entry)) {
write_logs();
}
});
@@ -260,6 +280,9 @@ private:
lambda(static_cast<Backend&>(debugger_backend));
lambda(static_cast<Backend&>(color_console_backend));
lambda(static_cast<Backend&>(file_backend));
+#ifdef ANDROID
+ lambda(static_cast<Backend&>(lc_backend));
+#endif
}
static void Deleter(Impl* ptr) {
@@ -272,8 +295,11 @@ private:
DebuggerBackend debugger_backend{};
ColorConsoleBackend color_console_backend{};
FileBackend file_backend;
+#ifdef ANDROID
+ LogcatBackend lc_backend{};
+#endif
- MPSCQueue<Entry, true> message_queue{};
+ MPSCQueue<Entry> message_queue{};
std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()};
std::jthread backend_thread;
};
diff --git a/src/common/logging/filter.cpp b/src/common/logging/filter.cpp
index a959acb74..c95909561 100644
--- a/src/common/logging/filter.cpp
+++ b/src/common/logging/filter.cpp
@@ -119,7 +119,7 @@ bool ParseFilterRule(Filter& instance, Iterator begin, Iterator end) {
SUB(Service, NPNS) \
SUB(Service, NS) \
SUB(Service, NVDRV) \
- SUB(Service, NVFlinger) \
+ SUB(Service, Nvnflinger) \
SUB(Service, OLSC) \
SUB(Service, PCIE) \
SUB(Service, PCTL) \
diff --git a/src/common/logging/text_formatter.cpp b/src/common/logging/text_formatter.cpp
index 09398ea64..2c453177b 100644
--- a/src/common/logging/text_formatter.cpp
+++ b/src/common/logging/text_formatter.cpp
@@ -8,6 +8,10 @@
#include <windows.h>
#endif
+#ifdef ANDROID
+#include <android/log.h>
+#endif
+
#include "common/assert.h"
#include "common/logging/filter.h"
#include "common/logging/log.h"
@@ -106,4 +110,35 @@ void PrintColoredMessage(const Entry& entry) {
#undef ESC
#endif
}
+
+void PrintMessageToLogcat(const Entry& entry) {
+#ifdef ANDROID
+ const auto str = FormatLogMessage(entry);
+
+ android_LogPriority android_log_priority;
+ switch (entry.log_level) {
+ case Level::Trace:
+ android_log_priority = ANDROID_LOG_VERBOSE;
+ break;
+ case Level::Debug:
+ android_log_priority = ANDROID_LOG_DEBUG;
+ break;
+ case Level::Info:
+ android_log_priority = ANDROID_LOG_INFO;
+ break;
+ case Level::Warning:
+ android_log_priority = ANDROID_LOG_WARN;
+ break;
+ case Level::Error:
+ android_log_priority = ANDROID_LOG_ERROR;
+ break;
+ case Level::Critical:
+ android_log_priority = ANDROID_LOG_FATAL;
+ break;
+ case Level::Count:
+ UNREACHABLE();
+ }
+ __android_log_print(android_log_priority, "YuzuNative", "%s", str.c_str());
+#endif
+}
} // namespace Common::Log
diff --git a/src/common/logging/text_formatter.h b/src/common/logging/text_formatter.h
index 0d0ec4370..68417420b 100644
--- a/src/common/logging/text_formatter.h
+++ b/src/common/logging/text_formatter.h
@@ -15,4 +15,6 @@ std::string FormatLogMessage(const Entry& entry);
void PrintMessage(const Entry& entry);
/// Prints the same message as `PrintMessage`, but colored according to the severity level.
void PrintColoredMessage(const Entry& entry);
+/// Formats and prints a log entry to the android logcat.
+void PrintMessageToLogcat(const Entry& entry);
} // namespace Common::Log
diff --git a/src/common/logging/types.h b/src/common/logging/types.h
index 595c15ada..8356e3183 100644
--- a/src/common/logging/types.h
+++ b/src/common/logging/types.h
@@ -29,107 +29,107 @@ enum class Level : u8 {
* filter.cpp.
*/
enum class Class : u8 {
- Log, ///< Messages about the log system itself
- Common, ///< Library routines
- Common_Filesystem, ///< Filesystem interface library
- Common_Memory, ///< Memory mapping and management functions
- Core, ///< LLE emulation core
- Core_ARM, ///< ARM CPU core
- Core_Timing, ///< CoreTiming functions
- Config, ///< Emulator configuration (including commandline)
- Debug, ///< Debugging tools
- Debug_Emulated, ///< Debug messages from the emulated programs
- Debug_GPU, ///< GPU debugging tools
- Debug_Breakpoint, ///< Logging breakpoints and watchpoints
- Debug_GDBStub, ///< GDB Stub
- Kernel, ///< The HLE implementation of the CTR kernel
- Kernel_SVC, ///< Kernel system calls
- Service, ///< HLE implementation of system services. Each major service
- ///< should have its own subclass.
- Service_ACC, ///< The ACC (Accounts) service
- Service_AM, ///< The AM (Applet manager) service
- Service_AOC, ///< The AOC (AddOn Content) service
- Service_APM, ///< The APM (Performance) service
- Service_ARP, ///< The ARP service
- Service_Audio, ///< The Audio (Audio control) service
- Service_BCAT, ///< The BCAT service
- Service_BGTC, ///< The BGTC (Background Task Controller) service
- Service_BPC, ///< The BPC service
- Service_BTDRV, ///< The Bluetooth driver service
- Service_BTM, ///< The BTM service
- Service_Capture, ///< The capture service
- Service_ERPT, ///< The error reporting service
- Service_ETicket, ///< The ETicket service
- Service_EUPLD, ///< The error upload service
- Service_Fatal, ///< The Fatal service
- Service_FGM, ///< The FGM service
- Service_Friend, ///< The friend service
- Service_FS, ///< The FS (Filesystem) service
- Service_GRC, ///< The game recording service
- Service_HID, ///< The HID (Human interface device) service
- Service_IRS, ///< The IRS service
- Service_JIT, ///< The JIT service
- Service_LBL, ///< The LBL (LCD backlight) service
- Service_LDN, ///< The LDN (Local domain network) service
- Service_LDR, ///< The loader service
- Service_LM, ///< The LM (Logger) service
- Service_Migration, ///< The migration service
- Service_Mii, ///< The Mii service
- Service_MM, ///< The MM (Multimedia) service
- Service_MNPP, ///< The MNPP service
- Service_NCM, ///< The NCM service
- Service_NFC, ///< The NFC (Near-field communication) service
- Service_NFP, ///< The NFP service
- Service_NGCT, ///< The NGCT (No Good Content for Terra) service
- Service_NIFM, ///< The NIFM (Network interface) service
- Service_NIM, ///< The NIM service
- Service_NOTIF, ///< The NOTIF (Notification) service
- Service_NPNS, ///< The NPNS service
- Service_NS, ///< The NS services
- Service_NVDRV, ///< The NVDRV (Nvidia driver) service
- Service_NVFlinger, ///< The NVFlinger service
- Service_OLSC, ///< The OLSC service
- Service_PCIE, ///< The PCIe service
- Service_PCTL, ///< The PCTL (Parental control) service
- Service_PCV, ///< The PCV service
- Service_PM, ///< The PM service
- Service_PREPO, ///< The PREPO (Play report) service
- Service_PSC, ///< The PSC service
- Service_PTM, ///< The PTM service
- Service_SET, ///< The SET (Settings) service
- Service_SM, ///< The SM (Service manager) service
- Service_SPL, ///< The SPL service
- Service_SSL, ///< The SSL service
- Service_TCAP, ///< The TCAP service.
- Service_Time, ///< The time service
- Service_USB, ///< The USB (Universal Serial Bus) service
- Service_VI, ///< The VI (Video interface) service
- Service_WLAN, ///< The WLAN (Wireless local area network) service
- HW, ///< Low-level hardware emulation
- HW_Memory, ///< Memory-map and address translation
- HW_LCD, ///< LCD register emulation
- HW_GPU, ///< GPU control emulation
- HW_AES, ///< AES engine emulation
- IPC, ///< IPC interface
- Frontend, ///< Emulator UI
- Render, ///< Emulator video output and hardware acceleration
- Render_Software, ///< Software renderer backend
- Render_OpenGL, ///< OpenGL backend
- Render_Vulkan, ///< Vulkan backend
- Shader, ///< Shader recompiler
- Shader_SPIRV, ///< Shader SPIR-V code generation
- Shader_GLASM, ///< Shader GLASM code generation
- Shader_GLSL, ///< Shader GLSL code generation
- Audio, ///< Audio emulation
- Audio_DSP, ///< The HLE implementation of the DSP
- Audio_Sink, ///< Emulator audio output backend
- Loader, ///< ROM loader
- CheatEngine, ///< Memory manipulation and engine VM functions
- Crypto, ///< Cryptographic engine/functions
- Input, ///< Input emulation
- Network, ///< Network emulation
- WebService, ///< Interface to yuzu Web Services
- Count ///< Total number of logging classes
+ Log, ///< Messages about the log system itself
+ Common, ///< Library routines
+ Common_Filesystem, ///< Filesystem interface library
+ Common_Memory, ///< Memory mapping and management functions
+ Core, ///< LLE emulation core
+ Core_ARM, ///< ARM CPU core
+ Core_Timing, ///< CoreTiming functions
+ Config, ///< Emulator configuration (including commandline)
+ Debug, ///< Debugging tools
+ Debug_Emulated, ///< Debug messages from the emulated programs
+ Debug_GPU, ///< GPU debugging tools
+ Debug_Breakpoint, ///< Logging breakpoints and watchpoints
+ Debug_GDBStub, ///< GDB Stub
+ Kernel, ///< The HLE implementation of the CTR kernel
+ Kernel_SVC, ///< Kernel system calls
+ Service, ///< HLE implementation of system services. Each major service
+ ///< should have its own subclass.
+ Service_ACC, ///< The ACC (Accounts) service
+ Service_AM, ///< The AM (Applet manager) service
+ Service_AOC, ///< The AOC (AddOn Content) service
+ Service_APM, ///< The APM (Performance) service
+ Service_ARP, ///< The ARP service
+ Service_Audio, ///< The Audio (Audio control) service
+ Service_BCAT, ///< The BCAT service
+ Service_BGTC, ///< The BGTC (Background Task Controller) service
+ Service_BPC, ///< The BPC service
+ Service_BTDRV, ///< The Bluetooth driver service
+ Service_BTM, ///< The BTM service
+ Service_Capture, ///< The capture service
+ Service_ERPT, ///< The error reporting service
+ Service_ETicket, ///< The ETicket service
+ Service_EUPLD, ///< The error upload service
+ Service_Fatal, ///< The Fatal service
+ Service_FGM, ///< The FGM service
+ Service_Friend, ///< The friend service
+ Service_FS, ///< The FS (Filesystem) service
+ Service_GRC, ///< The game recording service
+ Service_HID, ///< The HID (Human interface device) service
+ Service_IRS, ///< The IRS service
+ Service_JIT, ///< The JIT service
+ Service_LBL, ///< The LBL (LCD backlight) service
+ Service_LDN, ///< The LDN (Local domain network) service
+ Service_LDR, ///< The loader service
+ Service_LM, ///< The LM (Logger) service
+ Service_Migration, ///< The migration service
+ Service_Mii, ///< The Mii service
+ Service_MM, ///< The MM (Multimedia) service
+ Service_MNPP, ///< The MNPP service
+ Service_NCM, ///< The NCM service
+ Service_NFC, ///< The NFC (Near-field communication) service
+ Service_NFP, ///< The NFP service
+ Service_NGCT, ///< The NGCT (No Good Content for Terra) service
+ Service_NIFM, ///< The NIFM (Network interface) service
+ Service_NIM, ///< The NIM service
+ Service_NOTIF, ///< The NOTIF (Notification) service
+ Service_NPNS, ///< The NPNS service
+ Service_NS, ///< The NS services
+ Service_NVDRV, ///< The NVDRV (Nvidia driver) service
+ Service_Nvnflinger, ///< The Nvnflinger service
+ Service_OLSC, ///< The OLSC service
+ Service_PCIE, ///< The PCIe service
+ Service_PCTL, ///< The PCTL (Parental control) service
+ Service_PCV, ///< The PCV service
+ Service_PM, ///< The PM service
+ Service_PREPO, ///< The PREPO (Play report) service
+ Service_PSC, ///< The PSC service
+ Service_PTM, ///< The PTM service
+ Service_SET, ///< The SET (Settings) service
+ Service_SM, ///< The SM (Service manager) service
+ Service_SPL, ///< The SPL service
+ Service_SSL, ///< The SSL service
+ Service_TCAP, ///< The TCAP service.
+ Service_Time, ///< The time service
+ Service_USB, ///< The USB (Universal Serial Bus) service
+ Service_VI, ///< The VI (Video interface) service
+ Service_WLAN, ///< The WLAN (Wireless local area network) service
+ HW, ///< Low-level hardware emulation
+ HW_Memory, ///< Memory-map and address translation
+ HW_LCD, ///< LCD register emulation
+ HW_GPU, ///< GPU control emulation
+ HW_AES, ///< AES engine emulation
+ IPC, ///< IPC interface
+ Frontend, ///< Emulator UI
+ Render, ///< Emulator video output and hardware acceleration
+ Render_Software, ///< Software renderer backend
+ Render_OpenGL, ///< OpenGL backend
+ Render_Vulkan, ///< Vulkan backend
+ Shader, ///< Shader recompiler
+ Shader_SPIRV, ///< Shader SPIR-V code generation
+ Shader_GLASM, ///< Shader GLASM code generation
+ Shader_GLSL, ///< Shader GLSL code generation
+ Audio, ///< Audio emulation
+ Audio_DSP, ///< The HLE implementation of the DSP
+ Audio_Sink, ///< Emulator audio output backend
+ Loader, ///< ROM loader
+ CheatEngine, ///< Memory manipulation and engine VM functions
+ Crypto, ///< Cryptographic engine/functions
+ Input, ///< Input emulation
+ Network, ///< Network emulation
+ WebService, ///< Interface to yuzu Web Services
+ Count ///< Total number of logging classes
};
} // namespace Common::Log