Skip to content

Commit

Permalink
LogDir: Compress last logfile on restart
Browse files Browse the repository at this point in the history
For #7353
  • Loading branch information
ckamm committed Aug 1, 2019
1 parent fbf2e38 commit 907945d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/libsync/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void Logger::enterNextLogFile()

// Expire old log files and deal with conflicts
QStringList files = dir.entryList(QStringList("*owncloud.log.*"),
QDir::Files);
QDir::Files, QDir::Name);
QRegExp rx(R"(.*owncloud\.log\.(\d+).*)");
int maxNumber = -1;
foreach (const QString &s, files) {
Expand All @@ -286,10 +286,15 @@ void Logger::enterNextLogFile()
auto previousLog = _logFile.fileName();
setLogFile(dir.filePath(newLogName));

if (!previousLog.isEmpty()) {
QString compressedName = previousLog + ".gz";
if (compressLog(previousLog, compressedName)) {
QFile::remove(previousLog);
// Compress the previous log file. On a restart this can be the most recent
// log file.
auto logToCompress = previousLog;
if (logToCompress.isEmpty() && files.size() > 0 && !files.last().endsWith(".gz"))
logToCompress = dir.absoluteFilePath(files.last());
if (!logToCompress.isEmpty()) {
QString compressedName = logToCompress + ".gz";
if (compressLog(logToCompress, compressedName)) {
QFile::remove(logToCompress);
} else {
QFile::remove(compressedName);
}
Expand Down

0 comments on commit 907945d

Please sign in to comment.