From 3cee4308dc87b58918ad2594918d1cda574428d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Thu, 8 Feb 2018 12:37:22 +0100 Subject: logging: Break out QMessagePattern error reporting into standalone function Makes for a less awkward logic without any if (0) etc. Change-Id: I3db0984c5a0bbf1615c2feb2ebef59b4ec16e9ae Reviewed-by: Simon Hausmann Reviewed-by: Thiago Macieira --- src/corelib/global/qlogging.cpp | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) (limited to 'src/corelib/global') diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index 48d0cac10e..7e4425bd34 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -155,6 +155,7 @@ Q_NORETURN #endif static void qt_message_fatal(QtMsgType, const QMessageLogContext &context, const QString &message); static void qt_message_print(QtMsgType, const QMessageLogContext &context, const QString &message); +static void qt_message_print(const QString &message); static int checked_var_value(const char *varname) { @@ -1214,20 +1215,10 @@ void QMessagePattern::setPattern(const QString &pattern) error += QLatin1String("QT_MESSAGE_PATTERN: %{if-*} cannot be nested\n"); else if (inIf) error += QLatin1String("QT_MESSAGE_PATTERN: missing %{endif}\n"); - if (!error.isEmpty()) { -#if defined(Q_OS_WINRT) - OutputDebugString(reinterpret_cast(error.utf16())); - if (0) -#elif defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED) - if (!qt_logging_to_console()) { - OutputDebugString(reinterpret_cast(error.utf16())); - } else -#endif - { - fprintf(stderr, "%s", error.toLocal8Bit().constData()); - fflush(stderr); - } - } + + if (!error.isEmpty()) + qt_message_print(error); + literals = new const char*[literalsVar.size() + 1]; literals[literalsVar.size()] = 0; memcpy(literals, literalsVar.constData(), literalsVar.size() * sizeof(const char*)); @@ -1743,6 +1734,21 @@ static void qt_message_print(QtMsgType msgType, const QMessageLogContext &contex } } +static void qt_message_print(const QString &message) +{ +#if defined(Q_OS_WINRT) + OutputDebugString(reinterpret_cast(message.utf16())); + return; +#elif defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED) + if (!qt_logging_to_console()) { + OutputDebugString(reinterpret_cast(message.utf16())); + return; + } +#endif + fprintf(stderr, "%s", message.toLocal8Bit().constData()); + fflush(stderr); +} + static void qt_message_fatal(QtMsgType, const QMessageLogContext &context, const QString &message) { #if defined(Q_CC_MSVC) && defined(QT_DEBUG) && defined(_DEBUG) && defined(_CRT_ERROR) -- cgit v1.2.3