From b327830325cf8973ca293f566c05c17dfc177f46 Mon Sep 17 00:00:00 2001 From: Matthieu Gallien Date: Wed, 13 Nov 2024 11:54:36 +0100 Subject: [PATCH] flush logs every 5 lines written 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 --- src/libsync/logger.cpp | 8 +++++++- src/libsync/logger.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/libsync/logger.cpp b/src/libsync/logger.cpp index 5e885d7afebe4..a9ffad0f348c0 100644 --- a/src/libsync/logger.cpp +++ b/src/libsync/logger.cpp @@ -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) { @@ -145,8 +146,13 @@ void Logger::doLog(QtMsgType type, const QMessageLogContext &ctx, const QString if (_logstream) { (*_logstream) << msg << "\n"; - if (_doFileFlush) + ++_linesCounter; + if (_doFileFlush || + _linesCounter >= MaxLogLinesBeforeFlush || + type == QtMsgType::QtWarningMsg || type == QtMsgType::QtCriticalMsg || type == QtMsgType::QtFatalMsg) { _logstream->flush(); + _linesCounter = 0; + } } if (_permanentDeleteLogStream && ctx.category && strcmp(ctx.category, lcPermanentLog().categoryName()) == 0) { (*_permanentDeleteLogStream) << msg << "\n"; diff --git a/src/libsync/logger.h b/src/libsync/logger.h index 2d9dce3193edd..b913678b40172 100644 --- a/src/libsync/logger.h +++ b/src/libsync/logger.h @@ -110,6 +110,7 @@ public slots: QFile _logFile; bool _doFileFlush = false; + int _linesCounter = 0; int _logExpire = 0; bool _logDebug = false; QScopedPointer _logstream;