diff options
author | Jan Holthuis <jan.holthuis@ruhr-uni-bochum.de> | 2020-10-23 13:48:42 +0200 |
---|---|---|
committer | Jan Holthuis <jan.holthuis@ruhr-uni-bochum.de> | 2020-10-23 13:49:08 +0200 |
commit | 938c96281c904a9f8813c0f5af4acf76d4c84daa (patch) | |
tree | 64b40371f1a09fb50645c54e78a79be694a08e92 | |
parent | df034bd217719f1405566c97c559954f2c324307 (diff) |
logging: Fix handling of threadname in pattern
-rw-r--r-- | src/util/logging.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/util/logging.cpp b/src/util/logging.cpp index 514cf22687..e82c2715ab 100644 --- a/src/util/logging.cpp +++ b/src/util/logging.cpp @@ -30,6 +30,8 @@ QFile s_logfile; // Whether to break on debug assertions. bool s_debugAssertBreak = false; +const QString kThreadNamePattern = QStringLiteral("{{threadname}}"); + const QLoggingCategory kDefaultLoggingCategory = QLoggingCategory(nullptr); enum class WriteFlag { @@ -111,7 +113,7 @@ inline void writeToStdErr( bool flush) { QString formattedMessageStr = qFormatLogMessage(type, context, message) + QChar('\n'); const QByteArray formattedMessage = - formattedMessageStr.replace("{{threadname}}", threadName) + formattedMessageStr.replace(kThreadNamePattern, threadName) .toLocal8Bit(); QMutexLocker locked(&s_mutexStdErr); @@ -141,7 +143,9 @@ inline void writeToLog( QString threadName = QThread::currentThread()->objectName(); if (threadName.isEmpty()) { - threadName = QStringLiteral("%{qthreadptr}"); + threadName = QStringLiteral("0x") + + QString::number( + reinterpret_cast<size_t>(QThread::currentThread()), 16); } const bool flush = flags & WriteFlag::Flush; @@ -309,7 +313,8 @@ void Logging::initialize( // Set the default message pattern if the QT_MESSAGE_PATTERN variable is // not set. if (qgetenv("QT_MESSAGE_PATTERN").isEmpty()) { - qSetMessagePattern("%{type} [{{threadname}}] %{message}"); + qSetMessagePattern(QStringLiteral("%{type} [") + kThreadNamePattern + + QStringLiteral("] %{message}")); } // Install the Qt message handler. |