summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/logging/backend.cpp18
-rw-r--r--src/common/logging/backend.h15
2 files changed, 27 insertions, 6 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());
diff --git a/src/common/logging/backend.h b/src/common/logging/backend.h
index eb629a33f..826bde694 100644
--- a/src/common/logging/backend.h
+++ b/src/common/logging/backend.h
@@ -8,10 +8,13 @@
8#include <memory> 8#include <memory>
9#include <string> 9#include <string>
10#include <string_view> 10#include <string_view>
11#include "common/fs/file.h"
12#include "common/logging/filter.h" 11#include "common/logging/filter.h"
13#include "common/logging/log.h" 12#include "common/logging/log.h"
14 13
14namespace Common::FS {
15class IOFile;
16}
17
15namespace Common::Log { 18namespace Common::Log {
16 19
17class Filter; 20class Filter;
@@ -38,6 +41,7 @@ struct Entry {
38class Backend { 41class Backend {
39public: 42public:
40 virtual ~Backend() = default; 43 virtual ~Backend() = default;
44
41 virtual void SetFilter(const Filter& new_filter) { 45 virtual void SetFilter(const Filter& new_filter) {
42 filter = new_filter; 46 filter = new_filter;
43 } 47 }
@@ -53,6 +57,8 @@ private:
53 */ 57 */
54class ConsoleBackend : public Backend { 58class ConsoleBackend : public Backend {
55public: 59public:
60 ~ConsoleBackend() override;
61
56 static const char* Name() { 62 static const char* Name() {
57 return "console"; 63 return "console";
58 } 64 }
@@ -67,6 +73,8 @@ public:
67 */ 73 */
68class ColorConsoleBackend : public Backend { 74class ColorConsoleBackend : public Backend {
69public: 75public:
76 ~ColorConsoleBackend() override;
77
70 static const char* Name() { 78 static const char* Name() {
71 return "color_console"; 79 return "color_console";
72 } 80 }
@@ -83,6 +91,7 @@ public:
83class FileBackend : public Backend { 91class FileBackend : public Backend {
84public: 92public:
85 explicit FileBackend(const std::filesystem::path& filename); 93 explicit FileBackend(const std::filesystem::path& filename);
94 ~FileBackend() override;
86 95
87 static const char* Name() { 96 static const char* Name() {
88 return "file"; 97 return "file";
@@ -95,7 +104,7 @@ public:
95 void Write(const Entry& entry) override; 104 void Write(const Entry& entry) override;
96 105
97private: 106private:
98 FS::IOFile file; 107 std::unique_ptr<FS::IOFile> file;
99 std::size_t bytes_written = 0; 108 std::size_t bytes_written = 0;
100}; 109};
101 110
@@ -104,6 +113,8 @@ private:
104 */ 113 */
105class DebuggerBackend : public Backend { 114class DebuggerBackend : public Backend {
106public: 115public:
116 ~DebuggerBackend() override;
117
107 static const char* Name() { 118 static const char* Name() {
108 return "debugger"; 119 return "debugger";
109 } 120 }