From c150d63d54ce97fea41ec1cfe9224864b2a4b56c Mon Sep 17 00:00:00 2001 From: pjft Date: Tue, 1 Aug 2017 11:34:49 +0100 Subject: [PATCH] Backup previous session's Log file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Always keeps one session’s log backup file. --- es-app/src/main.cpp | 1 + es-core/src/Log.cpp | 9 +++++++++ es-core/src/Log.h | 1 + 3 files changed, 11 insertions(+) diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 49bd9c058..46085e591 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -222,6 +222,7 @@ int main(int argc, char* argv[]) return 1; //start the logger + Log::init(); Log::open(); LOG(LogInfo) << "EmulationStation - v" << PROGRAM_VERSION_STRING << ", built " << PROGRAM_BUILT_STRING; diff --git a/es-core/src/Log.cpp b/es-core/src/Log.cpp index 643aef16a..811bbb8cc 100644 --- a/es-core/src/Log.cpp +++ b/es-core/src/Log.cpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "platform.h" LogLevel Log::reportingLevel = LogInfo; @@ -23,6 +24,14 @@ void Log::setReportingLevel(LogLevel level) reportingLevel = level; } +void Log::init() +{ + remove((getLogPath() + ".bak").c_str()); + // rename previous log file + rename(getLogPath().c_str(), (getLogPath() + ".bak").c_str()); + return; +} + void Log::open() { file = fopen(getLogPath().c_str(), "w"); diff --git a/es-core/src/Log.h b/es-core/src/Log.h index fbc033d40..b0f985984 100644 --- a/es-core/src/Log.h +++ b/es-core/src/Log.h @@ -24,6 +24,7 @@ public: static std::string getLogPath(); static void flush(); + static void init(); static void open(); static void close(); protected: