Skip to content

Commit

Permalink
flush logs every 5 lines written
Browse files Browse the repository at this point in the history
should help not loosing too much logs in case of a crash or similar not
nominal stop of the client

Signed-off-by: Matthieu Gallien <[email protected]>
  • Loading branch information
mgallien committed Nov 19, 2024
1 parent 8268c0f commit 3ed32be
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/libsync/logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ namespace {

constexpr int CrashLogSize = 20;
constexpr auto MaxLogLinesCount = 50000;
constexpr auto MaxLogLinesBeforeFlush = 10;

static bool compressLog(const QString &originalName, const QString &targetName)
{
Expand Down Expand Up @@ -145,8 +146,11 @@ void Logger::doLog(QtMsgType type, const QMessageLogContext &ctx, const QString

if (_logstream) {
(*_logstream) << msg << "\n";
if (_doFileFlush)
++_linesCounter;
if (_doFileFlush || _linesCounter >= MaxLogLinesBeforeFlush) {
_logstream->flush();
_linesCounter = 0;
}
}
if (_permanentDeleteLogStream && ctx.category && strcmp(ctx.category, lcPermanentLog().categoryName()) == 0) {
(*_permanentDeleteLogStream) << msg << "\n";
Expand Down
1 change: 1 addition & 0 deletions src/libsync/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public slots:

QFile _logFile;
bool _doFileFlush = false;
int _linesCounter = 0;
int _logExpire = 0;
bool _logDebug = false;
QScopedPointer<QTextStream> _logstream;
Expand Down

0 comments on commit 3ed32be

Please sign in to comment.