From 9b800b55c1c4f2b3e6ed365736e357eb31423c95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 8 Feb 2018 12:44:29 +0100 Subject: logging: Break out stderr logging sink into separate function Change-Id: I4bc476376d2b84297c1798b016017db496532d27 Reviewed-by: Thiago Macieira --- src/corelib/global/qlogging.cpp | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) (limited to 'src/corelib/global/qlogging.cpp') diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index a860339473..ba0c105372 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -1244,7 +1244,7 @@ static QStringList backtraceFramesForLogMessage(int frameCount) static QRegularExpression rx(QStringLiteral("^(?:[^(]*/)?([^(/]+)\\(([^+]*)(?:[\\+[a-f0-9x]*)?\\) \\[[a-f0-9x]*\\]$"), QRegularExpression::OptimizeOnFirstUsageOption); - QVarLengthArray buffer(7 + frameCount); + QVarLengthArray buffer(8 + frameCount); int n = backtrace(buffer.data(), buffer.size()); if (n > 0) { int numberPrinted = 0; @@ -1638,6 +1638,19 @@ static bool win_message_handler(QtMsgType type, const QMessageLogContext &contex // -------------------------------------------------------------------------- +static void stderr_message_handler(QtMsgType type, const QMessageLogContext &context, const QString &message) +{ + QString formattedMessage = qFormatLogMessage(type, context, message); + + // print nothing if message pattern didn't apply / was empty. + // (still print empty lines, e.g. because message itself was empty) + if (formattedMessage.isNull()) + return; + + fprintf(stderr, "%s\n", formattedMessage.toLocal8Bit().constData()); + fflush(stderr); +} + /*! \internal */ @@ -1666,18 +1679,8 @@ static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &con # endif #endif - if (handledStderr) - return; - - QString formattedMessage = qFormatLogMessage(type, context, message); - - // print nothing if message pattern didn't apply / was empty. - // (still print empty lines, e.g. because message itself was empty) - if (formattedMessage.isNull()) - return; - - fprintf(stderr, "%s\n", formattedMessage.toLocal8Bit().constData()); - fflush(stderr); + if (!handledStderr) + stderr_message_handler(type, context, message); } /*! -- cgit v1.2.3