summaryrefslogtreecommitdiff
path: root/src/common/logging/backend.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common/logging/backend.cpp')
-rw-r--r--src/common/logging/backend.cpp18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 6aa8ac960..756b08dfe 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -17,6 +17,7 @@
17#endif 17#endif
18 18
19#include "common/assert.h" 19#include "common/assert.h"
20#include "common/fs/file.h"
20#include "common/fs/fs.h" 21#include "common/fs/fs.h"
21#include "common/logging/backend.h" 22#include "common/logging/backend.h"
22#include "common/logging/log.h" 23#include "common/logging/log.h"
@@ -140,10 +141,14 @@ private:
140 std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()}; 141 std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()};
141}; 142};
142 143
144ConsoleBackend::~ConsoleBackend() = default;
145
143void ConsoleBackend::Write(const Entry& entry) { 146void ConsoleBackend::Write(const Entry& entry) {
144 PrintMessage(entry); 147 PrintMessage(entry);
145} 148}
146 149
150ColorConsoleBackend::~ColorConsoleBackend() = default;
151
147void ColorConsoleBackend::Write(const Entry& entry) { 152void ColorConsoleBackend::Write(const Entry& entry) {
148 PrintColoredMessage(entry); 153 PrintColoredMessage(entry);
149} 154}
@@ -157,16 +162,19 @@ FileBackend::FileBackend(const std::filesystem::path& filename) {
157 void(FS::RemoveFile(old_filename)); 162 void(FS::RemoveFile(old_filename));
158 void(FS::RenameFile(filename, old_filename)); 163 void(FS::RenameFile(filename, old_filename));
159 164
160 file = FS::IOFile(filename, FS::FileAccessMode::Write, FS::FileType::TextFile); 165 file =
166 std::make_unique<FS::IOFile>(filename, FS::FileAccessMode::Write, FS::FileType::TextFile);
161} 167}
162 168
169FileBackend::~FileBackend() = default;
170
163void FileBackend::Write(const Entry& entry) { 171void FileBackend::Write(const Entry& entry) {
164 // prevent logs from going over the maximum size (in case its spamming and the user doesn't 172 // prevent logs from going over the maximum size (in case its spamming and the user doesn't
165 // know) 173 // know)
166 constexpr std::size_t MAX_BYTES_WRITTEN = 100 * 1024 * 1024; 174 constexpr std::size_t MAX_BYTES_WRITTEN = 100 * 1024 * 1024;
167 constexpr std::size_t MAX_BYTES_WRITTEN_EXTENDED = 1024 * 1024 * 1024; 175 constexpr std::size_t MAX_BYTES_WRITTEN_EXTENDED = 1024 * 1024 * 1024;
168 176
169 if (!file.IsOpen()) { 177 if (!file->IsOpen()) {
170 return; 178 return;
171 } 179 }
172 180
@@ -176,12 +184,14 @@ void FileBackend::Write(const Entry& entry) {
176 return; 184 return;
177 } 185 }
178 186
179 bytes_written += file.WriteString(FormatLogMessage(entry).append(1, '\n')); 187 bytes_written += file->WriteString(FormatLogMessage(entry).append(1, '\n'));
180 if (entry.log_level >= Level::Error) { 188 if (entry.log_level >= Level::Error) {
181 void(file.Flush()); 189 void(file->Flush());
182 } 190 }
183} 191}
184 192
193DebuggerBackend::~DebuggerBackend() = default;
194
185void DebuggerBackend::Write(const Entry& entry) { 195void DebuggerBackend::Write(const Entry& entry) {
186#ifdef _WIN32 196#ifdef _WIN32
187 ::OutputDebugStringW(UTF8ToUTF16W(FormatLogMessage(entry).append(1, '\n')).c_str()); 197 ::OutputDebugStringW(UTF8ToUTF16W(FormatLogMessage(entry).append(1, '\n')).c_str());