mirror of
https://github.com/yuzu-mirror/yuzu.git
synced 2024-11-17 19:17:33 +01:00
Merge pull request #1441 from CarlKenner/DebuggerLog
logging: Add DebuggerBackend for logging to Visual Studio
This commit is contained in:
commit
e10483a878
@ -12,7 +12,8 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
#include <share.h> // For _SH_DENYWR
|
#include <share.h> // For _SH_DENYWR
|
||||||
|
#include <windows.h> // For OutputDebugStringA
|
||||||
#else
|
#else
|
||||||
#define _SH_DENYWR 0
|
#define _SH_DENYWR 0
|
||||||
#endif
|
#endif
|
||||||
@ -139,12 +140,18 @@ void FileBackend::Write(const Entry& entry) {
|
|||||||
if (!file.IsOpen() || bytes_written > MAX_BYTES_WRITTEN) {
|
if (!file.IsOpen() || bytes_written > MAX_BYTES_WRITTEN) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
bytes_written += file.WriteString(FormatLogMessage(entry) + '\n');
|
bytes_written += file.WriteString(FormatLogMessage(entry).append(1, '\n'));
|
||||||
if (entry.log_level >= Level::Error) {
|
if (entry.log_level >= Level::Error) {
|
||||||
file.Flush();
|
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.
|
/// Macro listing all log classes. Code should define CLS and SUB as desired before invoking this.
|
||||||
#define ALL_LOG_CLASSES() \
|
#define ALL_LOG_CLASSES() \
|
||||||
CLS(Log) \
|
CLS(Log) \
|
||||||
|
@ -103,6 +103,20 @@ private:
|
|||||||
std::size_t bytes_written;
|
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> backend);
|
void AddBackend(std::unique_ptr<Backend> backend);
|
||||||
|
|
||||||
void RemoveBackend(std::string_view backend_name);
|
void RemoveBackend(std::string_view backend_name);
|
||||||
|
@ -142,6 +142,9 @@ static void InitializeLogging() {
|
|||||||
const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
|
const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
|
||||||
FileUtil::CreateFullPath(log_dir);
|
FileUtil::CreateFullPath(log_dir);
|
||||||
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
|
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
|
||||||
|
#ifdef _WIN32
|
||||||
|
Log::AddBackend(std::make_unique<Log::DebuggerBackend>());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
GMainWindow::GMainWindow()
|
GMainWindow::GMainWindow()
|
||||||
|
@ -76,6 +76,9 @@ static void InitializeLogging() {
|
|||||||
const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
|
const std::string& log_dir = FileUtil::GetUserPath(FileUtil::UserPath::LogDir);
|
||||||
FileUtil::CreateFullPath(log_dir);
|
FileUtil::CreateFullPath(log_dir);
|
||||||
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
|
Log::AddBackend(std::make_unique<Log::FileBackend>(log_dir + LOG_FILE));
|
||||||
|
#ifdef _WIN32
|
||||||
|
Log::AddBackend(std::make_unique<Log::DebuggerBackend>());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Application entry point
|
/// Application entry point
|
||||||
|
Loading…
Reference in New Issue
Block a user