mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-25 04:46:27 -05:00
common: logging: backend: Close the file after exceeding the write limit
There's no point in keeping the file open after the write limit is exceeded. This allows the file to be committed to the disk shortly after it is closed and avoids redundantly checking whether or not the write limit is exceeded.
This commit is contained in:
parent
14ab50defb
commit
a59ae5e702
1 changed files with 12 additions and 9 deletions
|
@ -171,19 +171,22 @@ FileBackend::FileBackend(const std::filesystem::path& filename) {
|
||||||
FileBackend::~FileBackend() = default;
|
FileBackend::~FileBackend() = default;
|
||||||
|
|
||||||
void FileBackend::Write(const Entry& entry) {
|
void FileBackend::Write(const Entry& entry) {
|
||||||
using namespace Common::Literals;
|
|
||||||
// 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_MiB;
|
|
||||||
constexpr std::size_t MAX_BYTES_WRITTEN_EXTENDED = 1_GiB;
|
|
||||||
|
|
||||||
if (!file->IsOpen()) {
|
if (!file->IsOpen()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Settings::values.extended_logging && bytes_written > MAX_BYTES_WRITTEN_EXTENDED) {
|
using namespace Common::Literals;
|
||||||
return;
|
// Prevent logs from exceeding a set maximum size in the event that log entries are spammed.
|
||||||
} else if (!Settings::values.extended_logging && bytes_written > MAX_BYTES_WRITTEN) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue