Log: Write the sync log during propagation #3108

...instead of when done with the sync. This way we get information
even if the client crashes.
This commit is contained in:
Christian Kamm 2016-06-09 14:10:47 +02:00
parent 87b4693a9d
commit 85a173e174
4 changed files with 19 additions and 19 deletions

View file

@ -70,6 +70,7 @@ Folder::Folder(const FolderDefinition& definition,
, _consecutiveFailingSyncs(0)
, _consecutiveFollowUpSyncs(0)
, _journal(definition.localPath)
, _fileLog(new SyncRunFileLog)
{
qRegisterMetaType<SyncFileItemVector>("SyncFileItemVector");
qRegisterMetaType<SyncFileItem::Direction>("SyncFileItem::Direction");
@ -370,18 +371,11 @@ void Folder::bubbleUpSyncResult()
SyncFileItemPtr firstConflictItem;
SyncFileItemPtr firstItemError;
SyncRunFileLog syncFileLog;
syncFileLog.start(path(), _engine->isSyncRunning() ? _engine->stopWatch() : Utility::StopWatch() );
QElapsedTimer timer;
timer.start();
foreach (const SyncFileItemPtr &item, _syncResult.syncFileItemVector() ) {
// Log the item
syncFileLog.logItem( *item );
// and process the item to the gui
// Process the item to the gui
if( item->_status == SyncFileItem::FatalError || item->_status == SyncFileItem::NormalError ) {
//: this displays an error string (%2) for a file %1
slotSyncError( tr("%1: %2").arg(item->_file, item->_errorString) );
@ -446,7 +440,6 @@ void Folder::bubbleUpSyncResult()
}
}
}
syncFileLog.close();
qDebug() << "Processing result list and logging took " << timer.elapsed() << " Milliseconds.";
_syncResult.setWarnCount(ignoredItems);
@ -762,6 +755,8 @@ void Folder::startSync(const QStringList &pathList)
_engine->setIgnoreHiddenFiles(_definition.ignoreHiddenFiles);
_fileLog->start(path());
QMetaObject::invokeMethod(_engine.data(), "startSync", Qt::QueuedConnection);
// disable events until syncing is done
@ -825,6 +820,7 @@ void Folder::slotSyncFinished(bool success)
} else {
qDebug() << "-> SyncEngine finished without problem.";
}
_fileLog->finish();
bubbleUpSyncResult();
bool anotherSyncNeeded = _engine->isAnotherSyncNeeded();
@ -931,6 +927,7 @@ void Folder::slotItemCompleted(const SyncFileItem &item, const PropagatorJob& jo
// Count all error conditions.
_syncResult.setWarnCount(_syncResult.warnCount()+1);
}
_fileLog->logItem(item);
emit ProgressDispatcher::instance()->itemCompleted(alias(), item, job);
}

View file

@ -35,6 +35,7 @@ namespace OCC {
class SyncEngine;
class AccountState;
class SyncRunFileLog;
/**
* @brief The FolderDefinition class
@ -311,6 +312,8 @@ private:
SyncJournalDb _journal;
ClientProxy _clientProxy;
QScopedPointer<SyncRunFileLog> _fileLog;
};
}

View file

@ -87,7 +87,7 @@ QString SyncRunFileLog::instructionToStr( csync_instructions_e inst )
}
void SyncRunFileLog::start(const QString &folderPath, const Utility::StopWatch &stopWatch )
void SyncRunFileLog::start(const QString &folderPath)
{
const qint64 logfileMaxSize = 1024*1024; // 1MiB
@ -108,8 +108,6 @@ void SyncRunFileLog::start(const QString &folderPath, const Utility::StopWatch
_file->open(QIODevice::WriteOnly | QIODevice::Append | QIODevice::Text);
_out.setDevice( _file.data() );
QDateTime dt = stopWatch.startTime();
QDateTime de = stopWatch.timeOfLap(QLatin1String("Sync Finished"));
if (!exists) {
// We are creating a new file, add the note.
@ -122,8 +120,8 @@ void SyncRunFileLog::start(const QString &folderPath, const Utility::StopWatch
}
_out << "#=#=#=# Syncrun started " << dateTimeStr(dt) << " until " << dateTimeStr(de) << " ("
<< stopWatch.durationOfLap(QLatin1String("Sync Finished")) << " msec)" << endl;
_duration.start();
_out << "#=#=#=# Syncrun started " << dateTimeStr(QDateTime::currentDateTime()) << endl;
}
void SyncRunFileLog::logItem( const SyncFileItem& item )
@ -162,8 +160,10 @@ void SyncRunFileLog::logItem( const SyncFileItem& item )
_out << endl;
}
void SyncRunFileLog::close()
void SyncRunFileLog::finish()
{
_out << "#=#=#=# Syncrun finished " << dateTimeStr(QDateTime::currentDateTime())
<< " (duration: " << _duration.elapsed() << " msec)" << endl;
_file->close();
}

View file

@ -17,9 +17,9 @@
#include <QFile>
#include <QTextStream>
#include <QScopedPointer>
#include <QElapsedTimer>
#include "syncfileitem.h"
#include "utility.h"
namespace OCC {
class SyncFileItem;
@ -32,9 +32,9 @@ class SyncRunFileLog
{
public:
SyncRunFileLog();
void start( const QString& folderPath, const Utility::StopWatch& stopWatch );
void start( const QString& folderPath );
void logItem( const SyncFileItem& item );
void close();
void finish();
protected:
@ -45,7 +45,7 @@ private:
QScopedPointer<QFile> _file;
QTextStream _out;
QElapsedTimer _duration;
};
}