summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorBernd Weimer <bweimer@blackberry.com>2014-04-07 17:46:31 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-24 10:15:24 +0200
commitd5a4732c1a4ae85e0e3adf9519209e69defb8f68 (patch)
tree02f7cb3eea66ef0127e4a2939b99a5005727f06d /src/corelib
parenta564b4e70a4635cea69bd3279abf16ede86137ef (diff)
Allow logging to stderr
Introduced a new environment variable "QT_LOGGING_TO_CONSOLE". When set on QNX for instance, log output is directed to the console instead of slog2. This can be more convenient when working on the command line. Besides, many declarative auto tests expect that, as well. Marked QT_NO_JOURNALD_LOG and QT_ANDROID_PLAIN_LOG as deprecated, to be replaced with QT_LOGGING_TO_CONSOLE. Change-Id: I7329fa2d10d31506eff145e956eaaa45d94f8e20 Reviewed-by: Fabian Bumberger <fbumberger@rim.com> Reviewed-by: BogDan Vatra <bogdan@kde.org> Reviewed-by: Robin Burchell <robin+qt@viroteck.net> Reviewed-by: Kai Koehne <kai.koehne@digia.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/global/qlogging.cpp36
1 files changed, 30 insertions, 6 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index da26490d18..4a602e4b2b 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -1207,6 +1207,23 @@ static void android_default_message_handler(QtMsgType type,
static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &context,
const QString &buf)
{
+ // to determine logging destination and marking logging environment variable as deprecated
+ // ### remove when deprecated
+ struct LogDestination {
+ LogDestination(const char *deprecated, bool forceConsole) {
+ const char* replacement = "QT_LOGGING_TO_CONSOLE";
+ bool newEnv = qEnvironmentVariableIsSet(replacement);
+ bool oldEnv = qEnvironmentVariableIsSet(deprecated);
+ if (oldEnv && !newEnv && !forceConsole) {
+ fprintf(stderr, "Warning: Environment variable %s is deprecated, "
+ "use %s instead.\n", deprecated, replacement);
+ fflush(stderr);
+ }
+ toConsole = newEnv || oldEnv || forceConsole;
+ }
+ bool toConsole;
+ };
+
QString logMessage = qMessageFormatString(type, context, buf);
#if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB)
@@ -1217,12 +1234,19 @@ static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &con
#endif // Q_OS_WIN
#if defined(QT_USE_SLOG2)
- slog2_default_handler(type, logMessage.toLocal8Bit().constData());
+ static const bool logToConsole = qEnvironmentVariableIsSet("QT_LOGGING_TO_CONSOLE");
+ if (!logToConsole) {
+ slog2_default_handler(type, logMessage.toLocal8Bit().constData());
+ } else {
+ fprintf(stderr, "%s", logMessage.toLocal8Bit().constData());
+ fflush(stderr);
+ }
#elif defined(QT_USE_JOURNALD) && !defined(QT_BOOTSTRAPPED)
// We use isatty to catch the obvious case of someone running something interactively.
- // We also support an environment variable for Qt Creator use, or more complicated cases like subprocesses.
- static bool logToConsole = isatty(fileno(stdin)) || !qEnvironmentVariableIsEmpty("QT_NO_JOURNALD_LOG");
- if (Q_LIKELY(!logToConsole)) {
+ // We also support environment variables for Qt Creator use, or more complicated cases
+ // like subprocesses.
+ static const LogDestination logdest("QT_NO_JOURNALD_LOG", isatty(fileno(stdin)));
+ if (Q_LIKELY(!logdest.toConsole)) {
// remove trailing \n, systemd appears to want them newline-less
logMessage.chop(1);
systemd_default_message_handler(type, context, logMessage);
@@ -1231,8 +1255,8 @@ static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &con
fflush(stderr);
}
#elif defined(Q_OS_ANDROID)
- static bool logToAndroid = qEnvironmentVariableIsEmpty("QT_ANDROID_PLAIN_LOG");
- if (logToAndroid) {
+ static const LogDestination logdest("QT_ANDROID_PLAIN_LOG", false);
+ if (!logdest.toConsole) {
android_default_message_handler(type, context, logMessage);
} else {
fprintf(stderr, "%s", logMessage.toLocal8Bit().constData());