diff --git a/src/main.cpp b/src/main.cpp index 05abac6e8..e598adf83 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -127,8 +128,28 @@ 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.remove(logFileDir + "qtox.log.1")) + qDebug() << "Removed log successfully"; + else + qDebug() << "Unable to remove old log file"; + + dir.rename(logFileDir + "qtox.log", logFileDir + "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 +268,6 @@ int main(int argc, char *argv[]) Nexus::destroyInstance(); CameraSource::destroyInstance(); Settings::destroyInstance(); - qDebug() << "Clean exit with status"<