only flush debug log files when closing them
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Mon, 12 Jun 2023 15:02:51 +0000 (17:02 +0200)
committerMatthieu Gallien <matthieu_gallien@yahoo.fr>
Wed, 23 Aug 2023 08:50:16 +0000 (10:50 +0200)
do not force a flush every time a log line is added to a file to speed
up the logging process

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/libsync/logger.cpp

index 8cd029cf9b1e03ff937ef4df7925a2613c06b70a..7a050a10360849c8c3b6567ade44ff0fd5491f20 100644 (file)
@@ -89,6 +89,9 @@ Logger::Logger(QObject *parent)
 
 Logger::~Logger()
 {
+    if (_logstream) {
+        _logstream->flush();
+    }
 #ifndef NO_MSG_HANDLER
     qInstallMessageHandler(nullptr);
 #endif
@@ -144,6 +147,9 @@ void Logger::doLog(QtMsgType type, const QMessageLogContext &ctx, const QString
 
         if (linesCounter >= MaxLogLinesCount) {
             linesCounter = 0;
+            if (_logstream) {
+                _logstream->flush();
+            }
             closeNoLock();
             enterNextLogFileNoLock();
         }
@@ -153,7 +159,7 @@ void Logger::doLog(QtMsgType type, const QMessageLogContext &ctx, const QString
         _crashLog[_crashLogIndex] = msg;
 
         if (_logstream) {
-            (*_logstream) << msg << Qt::endl;
+            (*_logstream) << msg << "\n";
             if (_doFileFlush)
                 _logstream->flush();
         }