Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[qtbase] Allow reinitializing logging. Contributes to JB#52717
We need this in MDeclarativeCache of mapplauncherd-qt5 to reload the
rules and other logging options after environment variables have been
updated.

Signed-off-by: Tomi Leppänen <tomi.leppanen@jolla.com>
  • Loading branch information
Tomin1 committed Feb 19, 2021
1 parent e1ae027 commit aec7599
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions src/corelib/global/qlogging.cpp
Expand Up @@ -147,18 +147,29 @@ Q_NORETURN
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 bool fatalCriticalsInitialized = false;
static bool fatalWarningsInitialized = false;

static bool isFatal(QtMsgType msgType)
{
if (msgType == QtFatalMsg)
return true;

if (msgType == QtCriticalMsg) {
static bool fatalCriticals = !qEnvironmentVariableIsEmpty("QT_FATAL_CRITICALS");
static bool fatalCriticals = false;
if (!fatalCriticalsInitialized) {
fatalCriticals = !qEnvironmentVariableIsEmpty("QT_FATAL_CRITICALS");
fatalCriticalsInitialized = true;
}
return fatalCriticals;
}

if (msgType == QtWarningMsg || msgType == QtCriticalMsg) {
static bool fatalWarnings = !qEnvironmentVariableIsEmpty("QT_FATAL_WARNINGS");
static bool fatalWarnings = false;
if (!fatalWarningsInitialized) {
fatalWarnings = !qEnvironmentVariableIsEmpty("QT_FATAL_WARNINGS");
fatalWarningsInitialized = true;
}
return fatalWarnings;
}

Expand Down Expand Up @@ -208,9 +219,15 @@ static bool willLogToConsole()
#endif
}

static bool logToConsoleInitialized = false;

Q_CORE_EXPORT bool qt_logging_to_console()
{
static const bool logToConsole = willLogToConsole();
static bool logToConsole = false;
if (!logToConsoleInitialized) {
logToConsole = willLogToConsole();
logToConsoleInitialized = true;
}
return logToConsole;
}

Expand Down Expand Up @@ -1908,4 +1925,24 @@ void QMessageLogContext::copy(const QMessageLogContext &logContext)
\a lineNumber, in function \a functionName, and category \a categoryName.
*/

/*!
\internal
For MDeclarativeCache.
*/
Q_CORE_EXPORT void qt_reinit_logging()
{
#ifndef QT_BOOTSTRAPPED
fatalCriticalsInitialized = false;
fatalWarningsInitialized = false;
logToConsoleInitialized = false;
QLoggingRegistry::instance()->init();
const QString envPattern = QString::fromLocal8Bit(qgetenv("QT_MESSAGE_PATTERN"));
if (!envPattern.isEmpty()) {
QMutexLocker lock(&QMessagePattern::mutex);
qMessagePattern()->setPattern(envPattern);
}
#endif
}

QT_END_NAMESPACE

0 comments on commit aec7599

Please sign in to comment.