summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Carl Kenner2018-10-05 12:52:49 +0930
committerGravatar Carl Kenner2018-10-07 13:24:04 +1030
commitf5f6292810dab70bc9be0fa4d9f37fe2b5544d86 (patch)
tree1ec449a6d6e33a36a3133de2196954a6967af9ad /src
parentMerge pull request #1450 from FearlessTobi/port-4312 (diff)
downloadyuzu-f5f6292810dab70bc9be0fa4d9f37fe2b5544d86.tar.gz
yuzu-f5f6292810dab70bc9be0fa4d9f37fe2b5544d86.tar.xz
yuzu-f5f6292810dab70bc9be0fa4d9f37fe2b5544d86.zip
logging: Add DebuggerBackend for logging to Visual Studio
Diffstat (limited to 'src')
-rw-r--r--src/common/logging/backend.cpp11
-rw-r--r--src/common/logging/backend.h14
-rw-r--r--src/yuzu/main.cpp3
-rw-r--r--src/yuzu_cmd/yuzu.cpp3
4 files changed, 29 insertions, 2 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 9f5918851..31ad72f38 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -12,7 +12,8 @@
12#include <thread> 12#include <thread>
13#include <vector> 13#include <vector>
14#ifdef _WIN32 14#ifdef _WIN32
15#include <share.h> // For _SH_DENYWR 15#include <share.h> // For _SH_DENYWR
16#include <windows.h> // For OutputDebugStringA
16#else 17#else
17#define _SH_DENYWR 0 18#define _SH_DENYWR 0
18#endif 19#endif
@@ -139,12 +140,18 @@ void FileBackend::Write(const Entry& entry) {
139 if (!file.IsOpen() || bytes_written > MAX_BYTES_WRITTEN) { 140 if (!file.IsOpen() || bytes_written > MAX_BYTES_WRITTEN) {
140 return; 141 return;
141 } 142 }
142 bytes_written += file.WriteString(FormatLogMessage(entry) + '\n'); 143 bytes_written += file.WriteString(FormatLogMessage(entry).append(1, '\n'));
143 if (entry.log_level >= Level::Error) { 144 if (entry.log_level >= Level::Error) {
144 file.Flush(); 145 file.Flush();
145 } 146 }
146} 147}
147 148
149void DebuggerBackend::Write(const Entry& entry) {
150#ifdef _WIN32
151 ::OutputDebugStringA(FormatLogMessage(entry).append(1, '\n').c_str());
152#endif
153}
154
148/// Macro listing all log classes. Code should define CLS and SUB as desired before invoking this. 155/// Macro listing all log classes. Code should define CLS and SUB as desired before invoking this.
149#define ALL_LOG_CLASSES() \ 156#define ALL_LOG_CLASSES() \
150 CLS(Log) \ 157 CLS(Log) \
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h
index 11edbf1b6..91bb0c309 100644
--- a/src/common/logging/backend.h
+++ b/src/common/logging/backend.h
@@ -103,6 +103,20 @@ private:
103 std::size_t bytes_written; 103 std::size_t bytes_written;
104}; 104};
105 105
106/**
107 * Backend that writes to Visual Studio's output window
108 */
109class DebuggerBackend : public Backend {
110public:
111 static const char* Name() {
112 return "debugger";
113 }
114 const char* GetName() const override {
115 return Name();
116 }
117 void Write(const Entry& entry) override;
118};
119
106void AddBackend(std::unique_ptr<Backend> backend); 120void AddBackend(std::unique_ptr<Backend> backend);
107 121
108void RemoveBackend(std::string_view backend_name); 122void RemoveBackend(std::string_view backend_name);
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index ad62a82d0..1d06d6c95 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -135,6 +135,9 @@ static void InitializeLogging() {
135 const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir); 135 const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
136 FileUtil::CreateFullPath(log_dir); 136 FileUtil::CreateFullPath(log_dir);
137 Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE)); 137 Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
138#ifdef _WIN32
139 Log::AddBackend(std::make_unique<Log::DebuggerBackend>());
140#endif
138} 141}
139 142
140GMainWindow::GMainWindow() 143GMainWindow::GMainWindow()
diff --git a/src/yuzu_cmd/yuzu.cpp b/src/yuzu_cmd/yuzu.cpp
index 1d951ca3f..bab465c1d 100644
--- a/src/yuzu_cmd/yuzu.cpp
+++ b/src/yuzu_cmd/yuzu.cpp
@@ -75,6 +75,9 @@ static void InitializeLogging() {
75 const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir); 75 const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
76 FileUtil::CreateFullPath(log_dir); 76 FileUtil::CreateFullPath(log_dir);
77 Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE)); 77 Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
78#ifdef _WIN32
79 Log::AddBackend(std::make_unique<Log::DebuggerBackend>());
80#endif
78} 81}
79 82
80/// Application entry point 83/// Application entry point