From e18b00593385fc1c003f4ee42681ea1d561d5032 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Tue, 22 Aug 2023 21:32:51 -0700 Subject: [PATCH] QLogging: switch the systemd/journald sink to unformatted mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The extra information is already stored in the journal metadata anyway, so there's no need to duplicate it. This matches the Apple Unified Logger output now. For most people, the visible difference will be that the category name is not included in the plain "journalctl" output. Aug 22 21:25:43 tjmaciei-mobl5 akonadi_imap_resource[4948]: org.kde.pim.kimap: Connection to server lost QAbstractSocket::HostNotFoundError Aug 22 21:27:17 tjmaciei-mobl5 kwin_x11[3376]: kwin_core: XCB error: 3 (BadWindow), sequence: 41165, resource id: 29363347, major code: 129 (SHAPE), minor code:> journalctl does not make it easy to show extra fields, but it's there and can be retrieved with -o verbose. [ChangeLog][QtCore][Logging] The Qt logging framework (qDebug/qWarning/etc) will now only send the plain, unformatted message to systemd's journald, if this backend is enabled. The category and other fields are sent via metadata to journald, so they can be filtered on and retrieved using journalctl. This matches what Qt does for the Apple Logging support and does not apply when Qt is using syslog or stderr to communicate with journald. Change-Id: Ifa1111900d6945ea8e05fffd177de8f47d74ba60 Reviewed-by: Kai Köhne --- src/corelib/global/qlogging.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp index d7b0f21b866..8364b5d224e 100644 --- a/src/corelib/global/qlogging.cpp +++ b/src/corelib/global/qlogging.cpp @@ -1796,7 +1796,7 @@ static bool slog2_default_handler(QtMsgType type, const QMessageLogContext &, #if QT_CONFIG(journald) static bool systemd_default_message_handler(QtMsgType type, const QMessageLogContext &context, - const QString &formattedMessage) + const QString &message) { if (shouldLogToStderr()) return false; // Leave logging up to stderr handler @@ -1820,7 +1820,7 @@ static bool systemd_default_message_handler(QtMsgType type, break; } - sd_journal_send("MESSAGE=%s", formattedMessage.toUtf8().constData(), + sd_journal_send("MESSAGE=%s", message.toUtf8().constData(), "PRIORITY=%i", priority, "CODE_FUNC=%s", context.function ? context.function : "unknown", "CODE_LINE=%d", context.line, @@ -2002,7 +2002,7 @@ static constexpr SystemMessageSink systemMessageSink = { #elif QT_CONFIG(slog2) slog2_default_handler #elif QT_CONFIG(journald) - systemd_default_message_handler + systemd_default_message_handler, true #elif QT_CONFIG(syslog) syslog_default_message_handler #elif defined(Q_OS_ANDROID)