summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qlogging.cpp
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@theqtcompany.com>2014-10-16 15:12:59 +0200
committerKai Koehne <kai.koehne@theqtcompany.com>2014-10-27 08:59:02 +0100
commit5bfe794aaab34d6aa021b5640972509e3bc6ced8 (patch)
tree3d4357aa5cb927c66aac33ecba59b0b36697d55a /src/corelib/global/qlogging.cpp
parent1ffe1a9a7c5199e46bf280806456a5d86f314169 (diff)
Remove trailing '\n' in qFormatLogMessage output
Do not automatically add a \n to all messages formatted by qFormatLogMessage. Some backends require a final newline, some don't, so it's best to only append it where it's actually needed. The returned string will be null if the pattern is empty. This allows to differentiate between the case that the pattern just didn't apply (empty line is printed), and the case that qSetMessagePattern(QString()) have been called (nothing is printed). Change-Id: I17fde997a4074f58f82de6dea129948155c322d6 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com> Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Diffstat (limited to 'src/corelib/global/qlogging.cpp')
-rw-r--r--src/corelib/global/qlogging.cpp19
1 files changed, 9 insertions, 10 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index f356bab42d..6def794d5e 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -1101,14 +1101,9 @@ QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context, con
if (!pattern) {
// after destruction of static QMessagePattern instance
message.append(str);
- message.append(QLatin1Char('\n'));
return message;
}
- // don't print anything if pattern was empty
- if (pattern->tokens[0] == 0)
- return message;
-
bool skip = false;
// we do not convert file, function, line literals to local encoding due to overhead
@@ -1227,7 +1222,6 @@ QString qFormatLogMessage(QtMsgType type, const QMessageLogContext &context, con
message.append(QLatin1String(token));
}
}
- message.append(QLatin1Char('\n'));
return message;
}
@@ -1289,7 +1283,7 @@ static void android_default_message_handler(QtMsgType type,
case QtFatalMsg: priority = ANDROID_LOG_FATAL; break;
};
- __android_log_print(priority, "Qt", "%s:%d (%s): %s",
+ __android_log_print(priority, "Qt", "%s:%d (%s): %s\n",
context.file, context.line,
context.function, qPrintable(message));
}
@@ -1303,16 +1297,21 @@ static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &con
{
QString logMessage = qFormatLogMessage(type, context, buf);
+ // print nothing if message pattern didn't apply / was empty.
+ // (still print empty lines, e.g. because message itself was empty)
+ if (logMessage.isNull())
+ return;
+
if (!qt_logging_to_console()) {
#if defined(Q_OS_WIN)
+ logMessage.append(QLatin1Char('\n'));
OutputDebugString(reinterpret_cast<const wchar_t *>(logMessage.utf16()));
return;
#elif defined(QT_USE_SLOG2)
+ logMessage.append(QLatin1Char('\n'));
slog2_default_handler(type, logMessage.toLocal8Bit().constData());
return;
#elif defined(QT_USE_JOURNALD) && !defined(QT_BOOTSTRAPPED)
- // remove trailing \n, systemd appears to want them newline-less
- logMessage.chop(1);
systemd_default_message_handler(type, context, logMessage);
return;
#elif defined(Q_OS_ANDROID)
@@ -1320,7 +1319,7 @@ static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &con
return;
#endif
}
- fprintf(stderr, "%s", logMessage.toLocal8Bit().constData());
+ fprintf(stderr, "%s\n", logMessage.toLocal8Bit().constData());
fflush(stderr);
}