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.cpp15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index d5cff400f..b6fa4affb 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -19,6 +19,8 @@
19#include "common/assert.h" 19#include "common/assert.h"
20#include "common/fs/file.h" 20#include "common/fs/file.h"
21#include "common/fs/fs.h" 21#include "common/fs/fs.h"
22#include "common/literals.h"
23
22#include "common/logging/backend.h" 24#include "common/logging/backend.h"
23#include "common/logging/log.h" 25#include "common/logging/log.h"
24#include "common/logging/text_formatter.h" 26#include "common/logging/text_formatter.h"
@@ -98,8 +100,8 @@ private:
98 write_logs(entry); 100 write_logs(entry);
99 } 101 }
100 102
101 // Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a case 103 // Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a
102 // where a system is repeatedly spamming logs even on close. 104 // case where a system is repeatedly spamming logs even on close.
103 const int MAX_LOGS_TO_WRITE = filter.IsDebug() ? INT_MAX : 100; 105 const int MAX_LOGS_TO_WRITE = filter.IsDebug() ? INT_MAX : 100;
104 int logs_written = 0; 106 int logs_written = 0;
105 while (logs_written++ < MAX_LOGS_TO_WRITE && message_queue.Pop(entry)) { 107 while (logs_written++ < MAX_LOGS_TO_WRITE && message_queue.Pop(entry)) {
@@ -159,7 +161,7 @@ FileBackend::FileBackend(const std::filesystem::path& filename) {
159 161
160 // Existence checks are done within the functions themselves. 162 // Existence checks are done within the functions themselves.
161 // We don't particularly care if these succeed or not. 163 // We don't particularly care if these succeed or not.
162 void(FS::RemoveFile(old_filename)); 164 FS::RemoveFile(old_filename);
163 void(FS::RenameFile(filename, old_filename)); 165 void(FS::RenameFile(filename, old_filename));
164 166
165 file = 167 file =
@@ -169,10 +171,11 @@ FileBackend::FileBackend(const std::filesystem::path& filename) {
169FileBackend::~FileBackend() = default; 171FileBackend::~FileBackend() = default;
170 172
171void FileBackend::Write(const Entry& entry) { 173void FileBackend::Write(const Entry& entry) {
174 using namespace Common::Literals;
172 // prevent logs from going over the maximum size (in case its spamming and the user doesn't 175 // prevent logs from going over the maximum size (in case its spamming and the user doesn't
173 // know) 176 // know)
174 constexpr std::size_t MAX_BYTES_WRITTEN = 100 * 1024 * 1024; 177 constexpr std::size_t MAX_BYTES_WRITTEN = 100_MiB;
175 constexpr std::size_t MAX_BYTES_WRITTEN_EXTENDED = 1024 * 1024 * 1024; 178 constexpr std::size_t MAX_BYTES_WRITTEN_EXTENDED = 1_GiB;
176 179
177 if (!file->IsOpen()) { 180 if (!file->IsOpen()) {
178 return; 181 return;
@@ -186,7 +189,7 @@ void FileBackend::Write(const Entry& entry) {
186 189
187 bytes_written += file->WriteString(FormatLogMessage(entry).append(1, '\n')); 190 bytes_written += file->WriteString(FormatLogMessage(entry).append(1, '\n'));
188 if (entry.log_level >= Level::Error) { 191 if (entry.log_level >= Level::Error) {
189 void(file->Flush()); 192 file->Flush();
190 } 193 }
191} 194}
192 195