diff options
Diffstat (limited to 'src/common/logging')
| -rw-r--r-- | src/common/logging/backend.cpp | 11 | ||||
| -rw-r--r-- | src/common/logging/backend.h | 14 |
2 files changed, 23 insertions, 2 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 6d5218465..5753b871a 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 | ||
| 149 | void 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 | */ | ||
| 109 | class DebuggerBackend : public Backend { | ||
| 110 | public: | ||
| 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 | |||
| 106 | void AddBackend(std::unique_ptr<Backend> backend); | 120 | void AddBackend(std::unique_ptr<Backend> backend); |
| 107 | 121 | ||
| 108 | void RemoveBackend(std::string_view backend_name); | 122 | void RemoveBackend(std::string_view backend_name); |