diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 4afba6833..3c8f8f54d 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -173,12 +173,19 @@ FileBackend::FileBackend(const std::string& 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 = 50 * 1024L * 1024L; - if (!file->IsOpen() || bytes_written > MAX_BYTES_WRITTEN) { + if (!file->IsOpen()) { return; } + + // Prevent logs from exceeding a set maximum size in the event that log entries are spammed. + constexpr std::size_t MAX_BYTES_WRITTEN = 50 * 1024L * 1024L; + + // Close the file after the write limit is exceeded. + if (bytes_written > MAX_BYTES_WRITTEN) { + file->Close(); + return; + } + bytes_written += file->WriteString(FormatLogMessage(entry).append(1, '\n')); if (entry.log_level >= Level::Error) { file->Flush();