Commit aec75990 authored by Tomi Leppänen's avatar Tomi Leppänen

[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's avatarTomi Leppänen <tomi.leppanen@jolla.com>
parent e1ae0272
......@@ -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;
}
......@@ -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;
}
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment