From fe5ba70e5571b75060e52973c5c96c77055a1794 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 7 Feb 2018 14:31:19 +0100 Subject: Prevent duplicated log output when using alternate logging sinks 3d02e75c07f was too quick, and didn't account for the fact that the old code had early returns for each alternate logging sink, so when removing the qt_logging_to_console() check, we would end up writing debug output twice. This is due to e.g. Qt Creator running the application without a console, so qt_logging_to_console() returns false, so we end up in e.g. the win_message_handler(), calling OutputDebugString, but then we unconditionally print to stderr, which Creator also reads, so we end up with duplicated log messages. Change-Id: I91573828576608643477ae27d36d7e819f92985d Reviewed-by: Laszlo Agocs Reviewed-by: Thiago Macieira --- src/corelib/global/qlogging.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'src/corelib/global/qlogging.cpp') diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index e2d08544a1..bad13a70b5 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -1371,7 +1371,7 @@ static bool slog2_default_handler(QtMsgType type, const QMessageLogContext &cont //writes to the slog2 buffer slog2c(NULL, QT_LOG_CODE, severity, formattedMessage.toLocal8Bit().constData()); - return false; + return true; // Prevent further output to stderr } #endif // slog2 @@ -1561,7 +1561,7 @@ static bool systemd_default_message_handler(QtMsgType type, "QT_CATEGORY=%s", context.category ? context.category : "unknown", NULL); - return false; + return true; // Prevent further output to stderr } #endif @@ -1594,7 +1594,7 @@ static bool syslog_default_message_handler(QtMsgType type, const QMessageLogCont syslog(priority, "%s", formattedMessage.toUtf8().constData()); - return false; + return true; // Prevent further output to stderr } #endif @@ -1621,7 +1621,7 @@ static bool android_default_message_handler(QtMsgType type, "%s:%d (%s): %s\n", context.file, context.line, context.function, qPrintable(formattedMessage)); - return false; + return true; // Prevent further output to stderr } #endif //Q_OS_ANDROID @@ -1634,7 +1634,8 @@ static bool win_message_handler(QtMsgType type, const QMessageLogContext &contex QString formattedMessage = qFormatLogMessage(type, context, message); formattedMessage.append(QLatin1Char('\n')); OutputDebugString(reinterpret_cast(formattedMessage.utf16())); - return false; + + return true; // Prevent further output to stderr } #endif -- cgit v1.2.3