Cleanup large log file on startup
This commit is contained in:
parent
4f68f85c90
commit
1ea50d7955
3 changed files with 14 additions and 0 deletions
|
@ -20,5 +20,6 @@ void logError(QString message);
|
||||||
void log(QString message, LogType type);
|
void log(QString message, LogType type);
|
||||||
QString getLogPath();
|
QString getLogPath();
|
||||||
QString getMostRecentError();
|
QString getMostRecentError();
|
||||||
|
bool cleanupLargeLog();
|
||||||
|
|
||||||
#endif // LOG_H
|
#endif // LOG_H
|
||||||
|
|
11
src/log.cpp
11
src/log.cpp
|
@ -86,3 +86,14 @@ QString getLogPath() {
|
||||||
QString getMostRecentError() {
|
QString getMostRecentError() {
|
||||||
return mostRecentError;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -53,6 +53,8 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||||
QApplication::setWindowIcon(QIcon(":/icons/porymap-icon-2.ico"));
|
QApplication::setWindowIcon(QIcon(":/icons/porymap-icon-2.ico"));
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
cleanupLargeLog();
|
||||||
|
|
||||||
this->initWindow();
|
this->initWindow();
|
||||||
if (!this->openRecentProject()) {
|
if (!this->openRecentProject()) {
|
||||||
// Re-initialize everything to a blank slate if opening the recent project failed.
|
// Re-initialize everything to a blank slate if opening the recent project failed.
|
||||||
|
|
Loading…
Reference in a new issue