Unify the environment variables used for console logging

[ChangeLog][Important behavior changes][Logging (including qDebug and
qWarning)] Support for the deprecated environment variables
QT_NO_JOURNALD_LOG and QT_ANDROID_PLAIN_LOG has been removed. Instead,
set QT_LOGGING_TO_CONSOLE to 1 to force logging to the console (stderr).
Set that variable to 0 to force logging to the system-specific event log
(if any).

Change-Id: I4800fc061752421f67aba1bf4535d524607579d5
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Thiago Macieira 2014-08-08 13:08:20 -03:00
parent d2349d8983
commit 85ad88b064

View File

@ -1275,23 +1275,6 @@ static void android_default_message_handler(QtMsgType type,
static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &context, static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &context,
const QString &buf) 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 = qFormatLogMessage(type, context, buf); QString logMessage = qFormatLogMessage(type, context, buf);
#if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB) #if defined(Q_OS_WIN) && defined(QT_BUILD_CORE_LIB)
@ -1301,8 +1284,8 @@ static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &con
} }
#endif // Q_OS_WIN #endif // Q_OS_WIN
#if defined(QT_USE_SLOG2)
static const bool logToConsole = qEnvironmentVariableIsSet("QT_LOGGING_TO_CONSOLE"); static const bool logToConsole = qEnvironmentVariableIsSet("QT_LOGGING_TO_CONSOLE");
#if defined(QT_USE_SLOG2)
if (!logToConsole) { if (!logToConsole) {
slog2_default_handler(type, logMessage.toLocal8Bit().constData()); slog2_default_handler(type, logMessage.toLocal8Bit().constData());
} else { } else {
@ -1310,11 +1293,9 @@ static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &con
fflush(stderr); fflush(stderr);
} }
#elif defined(QT_USE_JOURNALD) && !defined(QT_BOOTSTRAPPED) #elif defined(QT_USE_JOURNALD) && !defined(QT_BOOTSTRAPPED)
// We use isatty to catch the obvious case of someone running something interactively. // We support environment variables for Qt Creator use, or more complicated cases
// We also support environment variables for Qt Creator use, or more complicated cases
// like subprocesses. // like subprocesses.
static const LogDestination logdest("QT_NO_JOURNALD_LOG", isatty(fileno(stdin))); if (!logToConsole) {
if (Q_LIKELY(!logdest.toConsole)) {
// remove trailing \n, systemd appears to want them newline-less // remove trailing \n, systemd appears to want them newline-less
logMessage.chop(1); logMessage.chop(1);
systemd_default_message_handler(type, context, logMessage); systemd_default_message_handler(type, context, logMessage);
@ -1323,8 +1304,7 @@ static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &con
fflush(stderr); fflush(stderr);
} }
#elif defined(Q_OS_ANDROID) #elif defined(Q_OS_ANDROID)
static const LogDestination logdest("QT_ANDROID_PLAIN_LOG", false); if (!logToConsole) {
if (!logdest.toConsole) {
android_default_message_handler(type, context, logMessage); android_default_message_handler(type, context, logMessage);
} else { } else {
fprintf(stderr, "%s", logMessage.toLocal8Bit().constData()); fprintf(stderr, "%s", logMessage.toLocal8Bit().constData());
@ -1334,6 +1314,7 @@ static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &con
fprintf(stderr, "%s", logMessage.toLocal8Bit().constData()); fprintf(stderr, "%s", logMessage.toLocal8Bit().constData());
fflush(stderr); fflush(stderr);
#endif #endif
Q_UNUSED(logToConsole);
} }
/*! /*!