diff options
author | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2018-02-08 12:44:29 +0100 |
---|---|---|
committer | Tor Arne Vestbø <tor.arne.vestbo@qt.io> | 2018-02-11 03:32:25 +0000 |
commit | 9b800b55c1c4f2b3e6ed365736e357eb31423c95 (patch) | |
tree | 64348d8ac63e871ee3e49b45bd3902f0aeb35f2b | |
parent | a29e1fc708600aa8bdbce4163854574c0daab857 (diff) |
logging: Break out stderr logging sink into separate function
Change-Id: I4bc476376d2b84297c1798b016017db496532d27
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/global/qlogging.cpp | 29 |
1 files changed, 16 insertions, 13 deletions
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<void*, 32> buffer(7 + frameCount); + QVarLengthArray<void*, 32> 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); } /*! |