Added --logexpire to remove the log after some hours

This commit is contained in:
Olivier Goffart 2013-06-07 18:57:45 +02:00
parent b0f0d0b1cd
commit 779e59156c
2 changed files with 17 additions and 0 deletions

View File

@ -67,6 +67,8 @@ static const char optionsC[] =
" --logfile <filename> : write log output to file <filename>.\n"
" --logdir <name> : write each sync log output in a new file\n"
" in directory <name>.\n"
" --logexpire <hours> : removes logs older than <hours> 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 <dirname> : 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")) {

View File

@ -140,6 +140,7 @@ private:
LogBrowser *_logBrowser;
QString _logFile;
QString _logDirectory;
int _logExpire;
bool _showLogWindow;
bool _logFlush;
bool _helpOnly;