diff --git a/src/main.cpp b/src/main.cpp index 05abac6e8..9e2479876 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -127,8 +128,27 @@ int main(int argc, char *argv[]) sodium_init(); // For the auto-updater #ifdef LOG_TO_FILE + QString logFileDir = Settings::getInstance().getSettingsDirPath(); logFileStream.reset(new QTextStream); - logFileFile.reset(new QFile(Settings::getInstance().getSettingsDirPath()+"qtox.log")); + logFileFile.reset(new QFile(logFileDir + "qtox.log")); + + // Trim log file if over 1MB + if (logFileFile->size() > 1000000) { + qDebug() << "Log file over 1MB, rotating..."; + + QDir dir (logFileDir); + + // Check if log.1 already exists, and if so, delete it + if (dir.exists(logFileDir + "qtox.log.1")) { + dir.remove("qtox.log.1"); + } + + dir.rename("qtox.log", "qtox.log.1"); + + // Return to original log file path + logFileFile->setFileName(logFileDir + "qtox.log"); + } + if (logFileFile->open(QIODevice::Append)) { logFileStream->setDevice(logFileFile.get()); @@ -247,6 +267,6 @@ int main(int argc, char *argv[]) Nexus::destroyInstance(); CameraSource::destroyInstance(); Settings::destroyInstance(); - qDebug() << "Clean exit with status"<