fix(logger): brings back crash dump on fatal log output

originally using qFatal or qCFatal should have written a crash dump log
file

bring it back and ensure the crash would happen via the default Qt log
message handler

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
This commit is contained in:
Matthieu Gallien 2025-08-28 16:01:53 +02:00
parent 5d4c56a783
commit a4263b73e6
No known key found for this signature in database
GPG Key ID: 7D0F74F05C22F553

View File

@ -31,6 +31,8 @@ constexpr int CrashLogSize = 20;
constexpr auto MaxLogLinesCount = 50000;
constexpr auto MaxLogLinesBeforeFlush = 10;
static QtMessageHandler s_originalMessageHandler = nullptr;
static bool compressLog(const QString &originalName, const QString &targetName)
{
#ifdef ZLIB_FOUND
@ -76,7 +78,7 @@ Logger::Logger(QObject *parent)
"]%{if-debug}\t[ %{function} ]%{endif}:\t%{message}"));
_crashLog.resize(CrashLogSize);
#ifndef NO_MSG_HANDLER
qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &ctx, const QString &message) {
s_originalMessageHandler = qInstallMessageHandler([](QtMsgType type, const QMessageLogContext &ctx, const QString &message) {
Logger::instance()->doLog(type, ctx, message);
});
#endif
@ -159,7 +161,9 @@ void Logger::doLog(QtMsgType type, const QMessageLogContext &ctx, const QString
}
}
if (type == QtFatalMsg) {
dumpCrashLog();
closeNoLock();
s_originalMessageHandler(type, ctx, message);
#if defined(Q_OS_WIN)
// Make application terminate in a way that can be caught by the crash reporter
Utility::crash();
@ -171,7 +175,6 @@ void Logger::doLog(QtMsgType type, const QMessageLogContext &ctx, const QString
void Logger::closeNoLock()
{
dumpCrashLog();
if (_logstream)
{
_logstream->flush();