summaryrefslogtreecommitdiff
path: root/src/common/logging
diff options
context:
space:
mode:
authorGravatar Morph2021-07-05 12:54:06 -0400
committerGravatar Morph2021-07-06 05:59:47 -0400
commita59ae5e702a9fed1626e8815b2208acc7f373e22 (patch)
treedf07beed1c8a0d1ccd82ec9b42c54007c6a199ac /src/common/logging
parentcommon: fs: file: Revert Flush to its previous behavior and add Commit (diff)
downloadyuzu-a59ae5e702a9fed1626e8815b2208acc7f373e22.tar.gz
yuzu-a59ae5e702a9fed1626e8815b2208acc7f373e22.tar.xz
yuzu-a59ae5e702a9fed1626e8815b2208acc7f373e22.zip
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.
Diffstat (limited to 'src/common/logging')
-rw-r--r--src/common/logging/backend.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index b6fa4affb..61dddab3f 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -171,19 +171,22 @@ FileBackend::FileBackend(const std::filesystem::path& filename) {
171FileBackend::~FileBackend() = default; 171FileBackend::~FileBackend() = default;
172 172
173void FileBackend::Write(const Entry& entry) { 173void FileBackend::Write(const Entry& entry) {
174 if (!file->IsOpen()) {
175 return;
176 }
177
174 using namespace Common::Literals; 178 using namespace Common::Literals;
175 // prevent logs from going over the maximum size (in case its spamming and the user doesn't 179 // Prevent logs from exceeding a set maximum size in the event that log entries are spammed.
176 // know)
177 constexpr std::size_t MAX_BYTES_WRITTEN = 100_MiB; 180 constexpr std::size_t MAX_BYTES_WRITTEN = 100_MiB;
178 constexpr std::size_t MAX_BYTES_WRITTEN_EXTENDED = 1_GiB; 181 constexpr std::size_t MAX_BYTES_WRITTEN_EXTENDED = 1_GiB;
179 182
180 if (!file->IsOpen()) { 183 const bool write_limit_exceeded =
181 return; 184 bytes_written > MAX_BYTES_WRITTEN_EXTENDED ||
182 } 185 (bytes_written > MAX_BYTES_WRITTEN && !Settings::values.extended_logging);
183 186
184 if (Settings::values.extended_logging && bytes_written > MAX_BYTES_WRITTEN_EXTENDED) { 187 // Close the file after the write limit is exceeded.
185 return; 188 if (write_limit_exceeded) {
186 } else if (!Settings::values.extended_logging && bytes_written > MAX_BYTES_WRITTEN) { 189 file->Close();
187 return; 190 return;
188 } 191 }
189 192