summaryrefslogtreecommitdiffstats
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.cpp30
1 files changed, 18 insertions, 12 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index d5cff400f..61dddab3f 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -19,6 +19,8 @@
#include "common/assert.h"
#include "common/fs/file.h"
#include "common/fs/fs.h"
+#include "common/literals.h"
+
#include "common/logging/backend.h"
#include "common/logging/log.h"
#include "common/logging/text_formatter.h"
@@ -98,8 +100,8 @@ private:
write_logs(entry);
}
- // Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a case
- // where a system is repeatedly spamming logs even on close.
+ // Drain the logging queue. Only writes out up to MAX_LOGS_TO_WRITE to prevent a
+ // case where a system is repeatedly spamming logs even on close.
const int MAX_LOGS_TO_WRITE = filter.IsDebug() ? INT_MAX : 100;
int logs_written = 0;
while (logs_written++ < MAX_LOGS_TO_WRITE && message_queue.Pop(entry)) {
@@ -159,7 +161,7 @@ FileBackend::FileBackend(const std::filesystem::path& filename) {
// Existence checks are done within the functions themselves.
// We don't particularly care if these succeed or not.
- void(FS::RemoveFile(old_filename));
+ FS::RemoveFile(old_filename);
void(FS::RenameFile(filename, old_filename));
file =
@@ -169,24 +171,28 @@ FileBackend::FileBackend(const std::filesystem::path& filename) {
FileBackend::~FileBackend() = default;
void FileBackend::Write(const Entry& entry) {
- // prevent logs from going over the maximum size (in case its spamming and the user doesn't
- // know)
- constexpr std::size_t MAX_BYTES_WRITTEN = 100 * 1024 * 1024;
- constexpr std::size_t MAX_BYTES_WRITTEN_EXTENDED = 1024 * 1024 * 1024;
-
if (!file->IsOpen()) {
return;
}
- if (Settings::values.extended_logging && bytes_written > MAX_BYTES_WRITTEN_EXTENDED) {
- return;
- } else if (!Settings::values.extended_logging && bytes_written > MAX_BYTES_WRITTEN) {
+ using namespace Common::Literals;
+ // Prevent logs from exceeding a set maximum size in the event that log entries are spammed.
+ constexpr std::size_t MAX_BYTES_WRITTEN = 100_MiB;
+ constexpr std::size_t MAX_BYTES_WRITTEN_EXTENDED = 1_GiB;
+
+ const bool write_limit_exceeded =
+ bytes_written > MAX_BYTES_WRITTEN_EXTENDED ||
+ (bytes_written > MAX_BYTES_WRITTEN && !Settings::values.extended_logging);
+
+ // Close the file after the write limit is exceeded.
+ if (write_limit_exceeded) {
+ file->Close();
return;
}
bytes_written += file->WriteString(FormatLogMessage(entry).append(1, '\n'));
if (entry.log_level >= Level::Error) {
- void(file->Flush());
+ file->Flush();
}
}