diff --git a/src/mirall/application.cpp b/src/mirall/application.cpp index 29bb401ab7..009879ef25 100644 --- a/src/mirall/application.cpp +++ b/src/mirall/application.cpp @@ -67,6 +67,8 @@ static const char optionsC[] = " --logfile : write log output to file .\n" " --logdir : write each sync log output in a new file\n" " in directory .\n" + " --logexpire : removes logs older than hours.\n" + " (to be used with --logdir)\n" " --logflush : flush the log file after every write.\n" " --monoicons : Use black/white pictograms for systray.\n" " --confdir : Use the given configuration directory.\n" @@ -100,6 +102,7 @@ Application::Application(int &argc, char **argv) : _theme(Theme::instance()), _updateDetector(0), _logBrowser(0), + _logExpire(0), _showLogWindow(false), _logFlush(false), _helpOnly(false), @@ -575,9 +578,16 @@ void Application::enterNextLogFile() QDir::Files); QRegExp rx("owncloud.log.(\\d+)"); uint maxNumber = 0; + QDateTime now = QDateTime::currentDateTime(); foreach(const QString &s, files) { if (rx.exactMatch(s)) { maxNumber = qMax(maxNumber, rx.cap(1).toUInt()); + if (_logExpire > 0) { + QFileInfo fileInfo = dir.absoluteFilePath(s); + if (fileInfo.lastModified().addSecs(60*60 * _logExpire) < now) { + dir.remove(s); + } + } } } @@ -907,6 +917,12 @@ void Application::parseOptions(const QStringList &options) } else { setHelp(); } + } else if (option == QLatin1String("--logexpire")) { + if (it.hasNext() && !it.peekNext().startsWith(QLatin1String("--"))) { + _logExpire = it.next().toInt(); + } else { + setHelp(); + } } else if (option == QLatin1String("--logflush")) { _logFlush = true; } else if (option == QLatin1String("--monoicons")) { diff --git a/src/mirall/application.h b/src/mirall/application.h index 7d02626d14..0d2af0c828 100644 --- a/src/mirall/application.h +++ b/src/mirall/application.h @@ -140,6 +140,7 @@ private: LogBrowser *_logBrowser; QString _logFile; QString _logDirectory; + int _logExpire; bool _showLogWindow; bool _logFlush; bool _helpOnly;