diff --git a/include/log.h b/include/log.h index c908eee9..87e0ae01 100644 --- a/include/log.h +++ b/include/log.h @@ -20,5 +20,6 @@ void logError(QString message); void log(QString message, LogType type); QString getLogPath(); QString getMostRecentError(); +bool cleanupLargeLog(); #endif // LOG_H diff --git a/src/log.cpp b/src/log.cpp index 3b5d5eb0..64f6753a 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -86,3 +86,14 @@ QString getLogPath() { QString getMostRecentError() { return mostRecentError; } + +bool cleanupLargeLog() { + QFile logFile(getLogPath()); + if (logFile.size() < 20000000) + return false; + + bool removed = logFile.remove(); + if (removed) + logWarn(QString("Previous log file %1 was cleared due to being over 20MB in size.").arg(getLogPath())); + return removed; +} diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d98ed68a..e2ae8bdb 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -53,6 +53,8 @@ MainWindow::MainWindow(QWidget *parent) : QApplication::setWindowIcon(QIcon(":/icons/porymap-icon-2.ico")); ui->setupUi(this); + cleanupLargeLog(); + this->initWindow(); if (!this->openRecentProject()) { // Re-initialize everything to a blank slate if opening the recent project failed.