summaryrefslogtreecommitdiffstats
path: root/src/corelib/global/qlogging.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2023-08-23 12:15:29 -0700
committerThiago Macieira <thiago.macieira@intel.com>2023-10-24 04:04:19 -0700
commitdf2e07549e6edd1d271cce1d86cadd4a33dfd8fc (patch)
tree349ab2cb574f60902eaed18a4a32b35bc6bdeeb2 /src/corelib/global/qlogging.cpp
parent36805fc3c4383e8cf7b8f893d7402647da6deaf5 (diff)
QLogging: disable the message pattern functionality for bootstrap
We only have two tools that use the Bootstrap lib and neither of them need nor want the message pattern functionality. Change-Id: Ifa1111900d6945ea8e05fffd177e191ebb6afc4f Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
Diffstat (limited to 'src/corelib/global/qlogging.cpp')
-rw-r--r--src/corelib/global/qlogging.cpp37
1 files changed, 23 insertions, 14 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index 1991cc24647..50934701fa4 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -215,11 +215,6 @@ static bool isFatal(QtMsgType msgType)
return false;
}
-static bool isDefaultCategory(const char *category)
-{
- return !category || strcmp(category, "default") == 0;
-}
-
/*!
Returns true if writing to \c stderr is supported.
@@ -952,6 +947,12 @@ QDebug QMessageLogger::fatal(QMessageLogger::CategoryFunction catFunc) const
}
#endif // QT_NO_DEBUG_STREAM
+#if !defined(QT_BOOTSTRAPPED)
+static bool isDefaultCategory(const char *category)
+{
+ return !category || strcmp(category, "default") == 0;
+}
+
/*!
\internal
*/
@@ -1344,7 +1345,7 @@ void QMessagePattern::setPattern(const QString &pattern)
std::move(literalsVar.begin(), literalsVar.end(), &literals[0]);
}
-#if defined(QLOGGING_HAVE_BACKTRACE) && !defined(QT_BOOTSTRAPPED)
+#if defined(QLOGGING_HAVE_BACKTRACE)
// make sure the function has "Message" in the name so the function is removed
/*
A typical backtrace in debug mode looks like:
@@ -1547,12 +1548,10 @@ static QString formatLogMessage(QtMsgType type, const QMessageLogContext &contex
bool skip = false;
-#ifndef QT_BOOTSTRAPPED
int timeArgsIdx = 0;
#ifdef QLOGGING_HAVE_BACKTRACE
int backtraceArgsIdx = 0;
#endif
-#endif
// we do not convert file, function, line literals to local encoding due to overhead
for (int i = 0; pattern->tokens[i]; ++i) {
@@ -1562,14 +1561,12 @@ static QString formatLogMessage(QtMsgType type, const QMessageLogContext &contex
} else if (skip) {
// we skip adding messages, but we have to iterate over
// timeArgsIdx and backtraceArgsIdx anyway
-#ifndef QT_BOOTSTRAPPED
if (token == timeTokenC)
timeArgsIdx++;
#ifdef QLOGGING_HAVE_BACKTRACE
else if (token == backtraceTokenC)
backtraceArgsIdx++;
#endif
-#endif
} else if (token == messageTokenC) {
message.append(str);
} else if (token == categoryTokenC) {
@@ -1597,7 +1594,6 @@ static QString formatLogMessage(QtMsgType type, const QMessageLogContext &contex
message.append(QString::fromLatin1(qCleanupFuncinfo(context.function)));
else
message.append("unknown"_L1);
-#ifndef QT_BOOTSTRAPPED
} else if (token == pidTokenC) {
message.append(QString::number(QCoreApplication::applicationPid()));
} else if (token == appnameTokenC) {
@@ -1632,7 +1628,6 @@ static QString formatLogMessage(QtMsgType type, const QMessageLogContext &contex
message.append(QDateTime::currentDateTime().toString(timeFormat));
#endif // QT_CONFIG(datestring)
}
-#endif // !QT_BOOTSTRAPPED
} else if (token == ifCategoryTokenC) {
if (isDefaultCategory(context.category))
skip = true;
@@ -1651,6 +1646,14 @@ static QString formatLogMessage(QtMsgType type, const QMessageLogContext &contex
}
return message;
}
+#else // QT_BOOTSTRAPPED
+static QString formatLogMessage(QtMsgType type, const QMessageLogContext &context, const QString &str)
+{
+ Q_UNUSED(type);
+ Q_UNUSED(context);
+ return str;
+}
+#endif
static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &context, const QString &buf);
@@ -1973,7 +1976,12 @@ static void qDefaultMessageHandler(QtMsgType type, const QMessageLogContext &con
preformattedMessageHandler(type, context, formatLogMessage(type, context, message));
}
-#if defined(Q_COMPILER_THREAD_LOCAL)
+#if defined(QT_BOOTSTRAPPED)
+// there's no message handler in bootstrapped mode; force everything to stderr
+static bool grabMessageHandler() { return false; }
+static void ungrabMessageHandler() { }
+
+#elif defined(Q_COMPILER_THREAD_LOCAL)
Q_CONSTINIT static thread_local bool msgHandlerGrabbed = false;
@@ -2250,6 +2258,7 @@ QtMessageHandler qInstallMessageHandler(QtMessageHandler h)
return qDefaultMessageHandler;
}
+#ifndef QT_BOOTSTRAPPED
void qSetMessagePattern(const QString &pattern)
{
const auto locker = qt_scoped_lock(QMessagePattern::mutex);
@@ -2257,7 +2266,7 @@ void qSetMessagePattern(const QString &pattern)
if (!qMessagePattern()->fromEnvironment)
qMessagePattern()->setPattern(pattern);
}
-
+#endif
/*!
Copies context information from \a logContext into this QMessageLogContext.