From 34a3fedf7b115c84ff305bf72fbc9d568682d84a Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Sat, 21 Dec 2013 11:05:44 +0100 Subject: [PATCH] Keep the last five logs --- MultiMC.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/MultiMC.cpp b/MultiMC.cpp index 71a8fe592..5d08af4c9 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -280,12 +280,25 @@ void MultiMC::initTranslations() } } +void moveFile(const QString &oldName, const QString &newName) +{ + QFile::remove(newName); + QFile::copy(oldName, newName); + QFile::remove(oldName); +} void MultiMC::initLogger() { + static const QString logBase = "MultiMC-%0.log"; + + moveFile(logBase.arg(3), logBase.arg(4)); + moveFile(logBase.arg(2), logBase.arg(3)); + moveFile(logBase.arg(1), logBase.arg(2)); + moveFile(logBase.arg(0), logBase.arg(1)); + // init the logging mechanism QsLogging::Logger &logger = QsLogging::Logger::instance(); logger.setLoggingLevel(QsLogging::TraceLevel); - m_fileDestination = QsLogging::DestinationFactory::MakeFileDestination("MultiMC.log"); + m_fileDestination = QsLogging::DestinationFactory::MakeFileDestination(logBase.arg(0)); m_debugDestination = QsLogging::DestinationFactory::MakeQDebugDestination(); logger.addDestination(m_fileDestination.get()); logger.addDestination(m_debugDestination.get());