From f478a5773763a6d91f9263277ac394a7a9faaba3 Mon Sep 17 00:00:00 2001 From: xperia64 Date: Thu, 31 Dec 2020 16:10:01 -0500 Subject: Rotate previous log file to '.old' if it exists --- src/common/logging/backend.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 631f64d05..ebc807e00 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -145,10 +145,15 @@ void ColorConsoleBackend::Write(const Entry& entry) { PrintColoredMessage(entry); } -// _SH_DENYWR allows read only access to the file for other programs. -// It is #defined to 0 on other platforms -FileBackend::FileBackend(const std::string& filename) - : file(filename, "w", _SH_DENYWR), bytes_written(0) {} +FileBackend::FileBackend(const std::string& filename) : bytes_written(0) { + if (FileUtil::Exists(filename)) { + FileUtil::Rename(filename, filename + ".old"); + } + + // _SH_DENYWR allows read only access to the file for other programs. + // It is #defined to 0 on other platforms + file = FileUtil::IOFile(filename, "w", _SH_DENYWR); +} void FileBackend::Write(const Entry& entry) { // prevent logs from going over the maximum size (in case its spamming and the user doesn't -- cgit v1.2.3 From bf8bd60ab3da6db1bab4fe3bf3f0e9f66e95fb05 Mon Sep 17 00:00:00 2001 From: bunnei Date: Fri, 1 Jan 2021 03:17:20 -0800 Subject: Fix the old log file to work with the log parser. --- src/common/logging/backend.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index ebc807e00..7c9da6895 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -147,7 +147,7 @@ void ColorConsoleBackend::Write(const Entry& entry) { FileBackend::FileBackend(const std::string& filename) : bytes_written(0) { if (FileUtil::Exists(filename)) { - FileUtil::Rename(filename, filename + ".old"); + FileUtil::Rename(filename, filename + ".old.txt"); } // _SH_DENYWR allows read only access to the file for other programs. -- cgit v1.2.3 From fd5776aac21cee4ca8386c81d7d85d0a3c340fe8 Mon Sep 17 00:00:00 2001 From: xperia64 Date: Sun, 3 Jan 2021 19:53:23 +0000 Subject: Delete the old log file before rotating (#5675) --- src/common/logging/backend.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 7c9da6895..bec931ceb 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -146,6 +146,9 @@ void ColorConsoleBackend::Write(const Entry& entry) { } FileBackend::FileBackend(const std::string& filename) : bytes_written(0) { + if (FileUtil::Exists(filename + ".old.txt")) { + FileUtil::Delete(filename + ".old.txt"); + } if (FileUtil::Exists(filename)) { FileUtil::Rename(filename, filename + ".old.txt"); } -- cgit v1.2.3 From beb951770a920fce5d993c024402146aa0c92c34 Mon Sep 17 00:00:00 2001 From: FearlessTobi Date: Mon, 4 Jan 2021 04:36:50 +0100 Subject: Address review comments --- src/common/logging/backend.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index bec931ceb..2d4d2e9e7 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -146,16 +146,16 @@ void ColorConsoleBackend::Write(const Entry& entry) { } FileBackend::FileBackend(const std::string& filename) : bytes_written(0) { - if (FileUtil::Exists(filename + ".old.txt")) { - FileUtil::Delete(filename + ".old.txt"); + if (Common::FS::Exists(filename + ".old.txt")) { + Common::FS::Delete(filename + ".old.txt"); } - if (FileUtil::Exists(filename)) { - FileUtil::Rename(filename, filename + ".old.txt"); + if (Common::FS::Exists(filename)) { + Common::FS::Rename(filename, filename + ".old.txt"); } // _SH_DENYWR allows read only access to the file for other programs. // It is #defined to 0 on other platforms - file = FileUtil::IOFile(filename, "w", _SH_DENYWR); + file = Common::FS::IOFile(filename, "w", _SH_DENYWR); } void FileBackend::Write(const Entry& entry) { -- cgit v1.2.3