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 <simon.hausmann@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
bb10
Tor Arne Vestbø 2018-02-08 12:37:22 +01:00
parent c94ef51f0c
commit 3cee4308dc
1 changed files with 20 additions and 14 deletions

View File

@ -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<const wchar_t*>(error.utf16()));
if (0)
#elif defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED)
if (!qt_logging_to_console()) {
OutputDebugString(reinterpret_cast<const wchar_t*>(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<const wchar_t*>(message.utf16()));
return;
#elif defined(Q_OS_WIN) && !defined(QT_BOOTSTRAPPED)
if (!qt_logging_to_console()) {
OutputDebugString(reinterpret_cast<const wchar_t*>(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)