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.cpp39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index 4575df24d..96efa977d 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -21,11 +21,11 @@
21#include "common/logging/backend.h" 21#include "common/logging/backend.h"
22#include "common/logging/log.h" 22#include "common/logging/log.h"
23#include "common/logging/text_formatter.h" 23#include "common/logging/text_formatter.h"
24#include "common/settings.h"
24#include "common/string_util.h" 25#include "common/string_util.h"
25#include "common/threadsafe_queue.h" 26#include "common/threadsafe_queue.h"
26#include "core/settings.h"
27 27
28namespace Log { 28namespace Common::Log {
29 29
30/** 30/**
31 * Static state as a singleton. 31 * Static state as a singleton.
@@ -37,8 +37,11 @@ public:
37 return backend; 37 return backend;
38 } 38 }
39 39
40 Impl(Impl const&) = delete; 40 Impl(const Impl&) = delete;
41 const Impl& operator=(Impl const&) = delete; 41 Impl& operator=(const Impl&) = delete;
42
43 Impl(Impl&&) = delete;
44 Impl& operator=(Impl&&) = delete;
42 45
43 void PushEntry(Class log_class, Level log_level, const char* filename, unsigned int line_num, 46 void PushEntry(Class log_class, Level log_level, const char* filename, unsigned int line_num,
44 const char* function, std::string message) { 47 const char* function, std::string message) {
@@ -53,10 +56,10 @@ public:
53 56
54 void RemoveBackend(std::string_view backend_name) { 57 void RemoveBackend(std::string_view backend_name) {
55 std::lock_guard lock{writing_mutex}; 58 std::lock_guard lock{writing_mutex};
56 const auto it = 59
57 std::remove_if(backends.begin(), backends.end(), 60 std::erase_if(backends, [&backend_name](const auto& backend) {
58 [&backend_name](const auto& i) { return backend_name == i->GetName(); }); 61 return backend_name == backend->GetName();
59 backends.erase(it, backends.end()); 62 });
60 } 63 }
61 64
62 const Filter& GetGlobalFilter() const { 65 const Filter& GetGlobalFilter() const {
@@ -132,7 +135,7 @@ private:
132 std::mutex writing_mutex; 135 std::mutex writing_mutex;
133 std::thread backend_thread; 136 std::thread backend_thread;
134 std::vector<std::unique_ptr<Backend>> backends; 137 std::vector<std::unique_ptr<Backend>> backends;
135 Common::MPSCQueue<Log::Entry> message_queue; 138 MPSCQueue<Entry> message_queue;
136 Filter filter; 139 Filter filter;
137 std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()}; 140 std::chrono::steady_clock::time_point time_origin{std::chrono::steady_clock::now()};
138}; 141};
@@ -145,17 +148,19 @@ void ColorConsoleBackend::Write(const Entry& entry) {
145 PrintColoredMessage(entry); 148 PrintColoredMessage(entry);
146} 149}
147 150
148FileBackend::FileBackend(const std::string& filename) : bytes_written(0) { 151FileBackend::FileBackend(const std::string& filename) {
149 if (Common::FS::Exists(filename + ".old.txt")) { 152 const auto old_filename = filename + ".old.txt";
150 Common::FS::Delete(filename + ".old.txt"); 153
154 if (FS::Exists(old_filename)) {
155 FS::Delete(old_filename);
151 } 156 }
152 if (Common::FS::Exists(filename)) { 157 if (FS::Exists(filename)) {
153 Common::FS::Rename(filename, filename + ".old.txt"); 158 FS::Rename(filename, old_filename);
154 } 159 }
155 160
156 // _SH_DENYWR allows read only access to the file for other programs. 161 // _SH_DENYWR allows read only access to the file for other programs.
157 // It is #defined to 0 on other platforms 162 // It is #defined to 0 on other platforms
158 file = Common::FS::IOFile(filename, "w", _SH_DENYWR); 163 file = FS::IOFile(filename, "w", _SH_DENYWR);
159} 164}
160 165
161void FileBackend::Write(const Entry& entry) { 166void FileBackend::Write(const Entry& entry) {
@@ -182,7 +187,7 @@ void FileBackend::Write(const Entry& entry) {
182 187
183void DebuggerBackend::Write(const Entry& entry) { 188void DebuggerBackend::Write(const Entry& entry) {
184#ifdef _WIN32 189#ifdef _WIN32
185 ::OutputDebugStringW(Common::UTF8ToUTF16W(FormatLogMessage(entry).append(1, '\n')).c_str()); 190 ::OutputDebugStringW(UTF8ToUTF16W(FormatLogMessage(entry).append(1, '\n')).c_str());
186#endif 191#endif
187} 192}
188 193
@@ -342,4 +347,4 @@ void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename,
342 instance.PushEntry(log_class, log_level, filename, line_num, function, 347 instance.PushEntry(log_class, log_level, filename, line_num, function,
343 fmt::vformat(format, args)); 348 fmt::vformat(format, args));
344} 349}
345} // namespace Log 350} // namespace Common::Log