From: Kevin Ottens Date: Tue, 12 May 2020 15:33:13 +0000 (+0200) Subject: Don't silently kill debug messages X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~222^2^2~240^2 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=9000a880cb19090bfaf43f257d22b56aa9cd5902;p=nextcloud-desktop.git Don't silently kill debug messages The message handler globally installed by the logger silently drop messages if the logger is not logging. On top of it, it doesn't log debug messages by default. Anything not logged is currently silently discarded. This can come as a surprise to a developer trying to contribute for the first time and adding some debug message for some reason. We're thus trying to strike a middle ground which is that debug messages get a regular output if the logger isn't interested in them. Signed-off-by: Kevin Ottens --- diff --git a/src/libsync/logger.cpp b/src/libsync/logger.cpp index ef486266f..fb83259e5 100644 --- a/src/libsync/logger.cpp +++ b/src/libsync/logger.cpp @@ -25,10 +25,16 @@ namespace OCC { +QtMessageHandler s_originalMessageHandler = nullptr; + static void mirallLogCatcher(QtMsgType type, const QMessageLogContext &ctx, const QString &message) { auto logger = Logger::instance(); - if (!logger->isNoop()) { + if (type == QtDebugMsg && !logger->logDebug()) { + if (s_originalMessageHandler) { + s_originalMessageHandler(type, ctx, message); + } + } else if (!logger->isNoop()) { logger->doLog(qFormatLogMessage(type, ctx, message)); } } @@ -50,7 +56,7 @@ Logger::Logger(QObject *parent) { qSetMessagePattern("[%{function} \t%{message}"); #ifndef NO_MSG_HANDLER - qInstallMessageHandler(mirallLogCatcher); + s_originalMessageHandler = qInstallMessageHandler(mirallLogCatcher); #else Q_UNUSED(mirallLogCatcher) #endif