diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2021-11-23 17:01:09 +0300 |
---|---|---|
committer | Hannah von Reth <vonreth@kde.org> | 2021-11-25 13:13:35 +0300 |
commit | fa658b3b1e864b4a49d199035b009dd35b438b90 (patch) | |
tree | 39c932caa9044526ca34266c216b8845e51bc4bf /src/libsync | |
parent | 10be49238b57d2fb4ecd175eec910299dc47a745 (diff) |
Ensure we prooperly close the log file
We relied on the stack to destroy our logger which can have unreliable results.
Diffstat (limited to 'src/libsync')
-rw-r--r-- | src/libsync/logger.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/libsync/logger.cpp b/src/libsync/logger.cpp index c6d53ae0b..0d57b3cd1 100644 --- a/src/libsync/logger.cpp +++ b/src/libsync/logger.cpp @@ -16,6 +16,7 @@ #include "config.h" +#include <QCoreApplication> #include <QDir> #include <QStringList> #include <QtGlobal> @@ -52,8 +53,15 @@ namespace OCC { Logger *Logger::instance() { - static Logger log; - return &log; + static auto *log = [] { + auto log = new Logger; + qAddPostRoutine([] { + Logger::instance()->close(); + delete Logger::instance(); + }); + return log; + }(); + return log; } Logger::Logger(QObject *parent) @@ -104,6 +112,7 @@ void Logger::doLog(QtMsgType type, const QMessageLogContext &ctx, const QString } #endif if (type == QtFatalMsg) { + dumpCrashLog(); close(); #if defined(Q_OS_WIN) // Make application terminate in a way that can be caught by the crash reporter @@ -115,7 +124,6 @@ void Logger::doLog(QtMsgType type, const QMessageLogContext &ctx, const QString void Logger::close() { - dumpCrashLog(); if (_logstream) { _logstream->flush(); |