diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2021-06-15 12:11:29 +0300 |
---|---|---|
committer | Hannah von Reth <vonreth@kde.org> | 2021-06-15 14:28:52 +0300 |
commit | 4623e9126d57ad2506d2e10e258c8c10a4b4ce9d (patch) | |
tree | a5b8b21a305c51125da41fa0325503d3bc5dcb13 /src | |
parent | ed3969dce7e23875a5c296f98ef10b1f41841673 (diff) |
Use QDebug stream operators for .owncloudsync.log
Fixes: #8729
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/syncrunfilelog.cpp | 88 | ||||
-rw-r--r-- | src/gui/syncrunfilelog.h | 4 |
2 files changed, 42 insertions, 50 deletions
diff --git a/src/gui/syncrunfilelog.cpp b/src/gui/syncrunfilelog.cpp index 91cf61da2..496c8d892 100644 --- a/src/gui/syncrunfilelog.cpp +++ b/src/gui/syncrunfilelog.cpp @@ -12,6 +12,7 @@ * for more details. */ +#include <QDate> #include <QRegExp> #include "syncrunfilelog.h" @@ -19,45 +20,49 @@ #include "filesystem.h" #include <qfileinfo.h> +namespace { +auto dateTimeStr(const QDateTime &dt = QDateTime::currentDateTimeUtc()) +{ + return dt.toString(Qt::ISODate); +} + +} namespace OCC { SyncRunFileLog::SyncRunFileLog() { } -QString SyncRunFileLog::dateTimeStr(const QDateTime &dt) -{ - return dt.toString(Qt::ISODate); -} void SyncRunFileLog::start(const QString &folderPath) { const qint64 logfileMaxSize = 10 * 1024 * 1024; // 10MiB // Note; this name is ignored in csync_exclude.c - const QString filename = folderPath + QLatin1String(".owncloudsync.log"); + const QString filename = folderPath + QStringLiteral(".owncloudsync.log"); // When the file is too big, just rename it to an old name. QFileInfo info(filename); bool exists = info.exists(); if (exists && info.size() > logfileMaxSize) { exists = false; - QString newFilename = filename + QLatin1String(".1"); + QString newFilename = filename + QStringLiteral(".1"); QFile::remove(newFilename); QFile::rename(filename, newFilename); } _file.reset(new QFile(filename)); _file->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text); - _out.setDevice(_file.data()); + _out.reset(new QDebug(_file.data())); + _out->noquote(); if (!exists) { // We are creating a new file, add the note. - _out << "# timestamp | duration | file | instruction | dir | modtime | etag | " - "size | fileId | status | errorString | http result code | " - "other size | other modtime | X-Request-ID" - << endl; + *_out << "# timestamp | duration | file | instruction | dir | modtime | etag | " + "size | fileId | status | errorString | http result code | " + "other size | other modtime | X-Request-ID" + << endl; FileSystem::setFileHidden(filename, true); } @@ -65,7 +70,7 @@ void SyncRunFileLog::start(const QString &folderPath) _totalDuration.start(); _lapDuration.start(); - _out << "#=#=#=# Syncrun started " << dateTimeStr(QDateTime::currentDateTimeUtc()) << endl; + *_out << "#=#=#=# Syncrun started " << dateTimeStr() << endl; } void SyncRunFileLog::logItem(const SyncFileItem &item) @@ -75,50 +80,39 @@ void SyncRunFileLog::logItem(const SyncFileItem &item) || item._instruction == CSYNC_INSTRUCTION_IGNORE) { return; } - QString ts = QString::fromLatin1(item._responseTimeStamp); - if (ts.length() > 6) { - QRegExp rx("(\\d\\d:\\d\\d:\\d\\d)"); - if (ts.contains(rx)) { - ts = rx.cap(0); - } - } - const QChar L = QLatin1Char('|'); - _out << ts << L; - _out << L; - if (item._instruction != CSYNC_INSTRUCTION_RENAME) { - _out << item.destination() << L; - } else { - _out << item._file << QLatin1String(" -> ") << item._renameTarget << L; - } - _out << item._instruction << L; - _out << item._direction << L; - _out << QString::number(item._modtime) << L; - _out << item._etag << L; - _out << QString::number(item._size) << L; - _out << item._fileId << L; - _out << item._status << L; - _out << item._errorString << L; - _out << QString::number(item._httpErrorCode) << L; - _out << QString::number(item._previousSize) << L; - _out << QString::number(item._previousModtime) << L; - _out << item._requestId << L; - - _out << endl; + *_out << dateTimeStr(QDateTime::fromString(QString::fromUtf8(item._responseTimeStamp), Qt::RFC2822Date)) << L + << ((item._instruction != CSYNC_INSTRUCTION_RENAME) ? item.destination() : item._file + QStringLiteral(" -> ") + item._renameTarget) << L + << item._instruction << L + << item._direction << L + << L + << item._modtime << L + << item._etag << L + << item._size << L + << item._fileId << L + << item._status << L + << item._errorString << L + << item._httpErrorCode << L + << item._previousSize << L + << item._previousModtime << L + << item._requestId << L + << endl; } void SyncRunFileLog::logLap(const QString &name) { - _out << "#=#=#=#=# " << name << " " << dateTimeStr(QDateTime::currentDateTimeUtc()) - << " (last step: " << _lapDuration.restart() << " msec" - << ", total: " << _totalDuration.elapsed() << " msec)" << endl; + *_out << "#=#=#=#=#" << name << dateTimeStr() + << "(last step:" << _lapDuration.restart() << "msec" + << ", total:" << _totalDuration.elapsed() << "msec)" + << endl; } void SyncRunFileLog::finish() { - _out << "#=#=#=# Syncrun finished " << dateTimeStr(QDateTime::currentDateTimeUtc()) - << " (last step: " << _lapDuration.elapsed() << " msec" - << ", total: " << _totalDuration.elapsed() << " msec)" << endl; + *_out << "#=#=#=# Syncrun finished" << dateTimeStr() + << "(last step:" << _lapDuration.elapsed() << "msec" + << ", total:" << _totalDuration.elapsed() << "msec)" + << endl; _file->close(); } } diff --git a/src/gui/syncrunfilelog.h b/src/gui/syncrunfilelog.h index 7e4be4c76..8a5fb0e1d 100644 --- a/src/gui/syncrunfilelog.h +++ b/src/gui/syncrunfilelog.h @@ -40,12 +40,10 @@ public: protected: private: - QString dateTimeStr(const QDateTime &dt); - QScopedPointer<QFile> _file; - QTextStream _out; QElapsedTimer _totalDuration; QElapsedTimer _lapDuration; + QScopedPointer<QDebug> _out; }; } |