From f5f6292810dab70bc9be0fa4d9f37fe2b5544d86 Mon Sep 17 00:00:00 2001 From: Carl Kenner Date: Fri, 5 Oct 2018 12:52:49 +0930 Subject: [PATCH] logging: Add DebuggerBackend for logging to Visual Studio --- src/common/logging/backend.cpp | 11 +++++++++-- src/common/logging/backend.h | 14 ++++++++++++++ src/yuzu/main.cpp | 3 +++ src/yuzu_cmd/yuzu.cpp | 3 +++ 4 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 9f59188510..31ad72f386 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -12,7 +12,8 @@ #include #include #ifdef _WIN32 -#include // For _SH_DENYWR +#include // For _SH_DENYWR +#include // For OutputDebugStringA #else #define _SH_DENYWR 0 #endif @@ -139,12 +140,18 @@ void FileBackend::Write(const Entry& entry) { if (!file.IsOpen() || bytes_written > MAX_BYTES_WRITTEN) { return; } - bytes_written += file.WriteString(FormatLogMessage(entry) + '\n'); + bytes_written += file.WriteString(FormatLogMessage(entry).append(1, '\n')); if (entry.log_level >= Level::Error) { file.Flush(); } } +void DebuggerBackend::Write(const Entry& entry) { +#ifdef _WIN32 + ::OutputDebugStringA(FormatLogMessage(entry).append(1, '\n').c_str()); +#endif +} + /// Macro listing all log classes. Code should define CLS and SUB as desired before invoking this. #define ALL_LOG_CLASSES() \ CLS(Log) \ diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h index 11edbf1b6a..91bb0c309c 100644 --- a/src/common/logging/backend.h +++ b/src/common/logging/backend.h @@ -103,6 +103,20 @@ private: std::size_t bytes_written; }; +/** + * Backend that writes to Visual Studio's output window + */ +class DebuggerBackend : public Backend { +public: + static const char* Name() { + return "debugger"; + } + const char* GetName() const override { + return Name(); + } + void Write(const Entry& entry) override; +}; + void AddBackend(std::unique_ptr backend); void RemoveBackend(std::string_view backend_name); diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index ad62a82d0a..1d06d6c95a 100644 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -135,6 +135,9 @@ static void InitializeLogging() { const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir); FileUtil::CreateFullPath(log_dir); Log::AddBackend(std::make_unique(log_dir + LOG_FILE)); +#ifdef _WIN32 + Log::AddBackend(std::make_unique()); +#endif } GMainWindow::GMainWindow() diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp index 1d951ca3f1..bab465c1d6 100644 --- a/src/yuzu_cmd/yuzu.cpp +++ b/src/yuzu_cmd/yuzu.cpp @@ -75,6 +75,9 @@ static void InitializeLogging() { const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir); FileUtil::CreateFullPath(log_dir); Log::AddBackend(std::make_unique(log_dir + LOG_FILE)); +#ifdef _WIN32 + Log::AddBackend(std::make_unique()); +#endif } /// Application entry point