fix(logging): keep Qt's platform chatter out of the journal

Opening a dialog under Wayland made Qt write a burst of qt.qpa
warnings into the application journal — the text-input focus one,
repeated at every prompt — where the user can do nothing with them:
they describe the display server, not the application. Those
categories stay on stderr from now on, next to everything else, while
what the application logs (its own categories, and a bare qCWarning)
keeps going to the journal.
This commit is contained in:
BlackAngelTV committed 2026-10-09 19:22:19 +02:00
1 parent bea3d61045
commit f4aa661b54
4 files changed
+85 -15

No files matched your search

+25 -14
View File
@@ -229,6 +229,13 @@ bool LogManager::hasEntries() const {
return !readFile().isEmpty();
}
bool LogManager::journalsQtCategory(const QString& category) {
// Only the platform plugin is filtered. A category the application chose
// (pacmgr.*, the "default" one a bare qCWarning carries) describes what the
// app did and stays in the journal.
return !category.startsWith(QStringLiteral("qt.qpa"));
}
void LogManager::installQtMessageHandler() {
// Make sure the singleton is created on the calling (main) thread before any
// worker emits a log message.
@@ -237,23 +244,27 @@ void LogManager::installQtMessageHandler() {
qInstallMessageHandler([](QtMsgType type, const QMessageLogContext& context,
const QString& message) {
// Keep the usual console output too, so a developer still sees the logs
// in a terminal.
const char* category = context.category ? context.category : "default";
std::fprintf(stderr, "[%s] %s\n", category, message.toLocal8Bit().constData());
// in a terminal — including the platform chatter the journal leaves
// out.
const char* rawCategory = context.category ? context.category : "default";
std::fprintf(stderr, "[%s] %s\n", rawCategory, message.toLocal8Bit().constData());
QString level;
switch (type) {
case QtDebugMsg: level = QStringLiteral("debug"); break;
case QtInfoMsg: level = QStringLiteral("info"); break;
case QtWarningMsg: level = QCoreApplication::translate("LogManager", "avertissement"); break;
case QtCriticalMsg: level = QCoreApplication::translate("LogManager", "critique"); break;
case QtFatalMsg: level = QStringLiteral("fatal"); break;
const QString category = QString::fromLatin1(rawCategory);
if (journalsQtCategory(category)) {
QString level;
switch (type) {
case QtDebugMsg: level = QStringLiteral("debug"); break;
case QtInfoMsg: level = QStringLiteral("info"); break;
case QtWarningMsg: level = QCoreApplication::translate("LogManager", "avertissement"); break;
case QtCriticalMsg: level = QCoreApplication::translate("LogManager", "critique"); break;
case QtFatalMsg: level = QStringLiteral("fatal"); break;
}
LogManager::instance().logEvent(
QStringLiteral("qt/%1").arg(category),
QStringLiteral("%1: %2").arg(level, message));
}
LogManager::instance().logEvent(
QStringLiteral("qt/%1").arg(QString::fromLatin1(category)),
QStringLiteral("%1: %2").arg(level, message));
if (type == QtFatalMsg) std::abort();
});
}
+12 -1
View File
@@ -33,7 +33,9 @@
//
// Every Qt log message (qCDebug/qCInfo/qCWarning/qCCritical) is funnelled into
// the same journal by installQtMessageHandler(), so the categories already used
// across the code base feed it without extra plumbing.
// across the code base feed it without extra plumbing. Qt's own platform
// categories (`qt.qpa.*`) are the one exception: they describe the display
// server, not the application, and stay on stderr (see journalsQtCategory).
//
// The file lives in the user's own data tree (XDG_CONFIG_HOME / home) so it is
// never lost when a sandbox is rebuilt, and both that directory and a size cap
@@ -87,6 +89,15 @@ public:
// QApplication exists. Safe to call more than once.
static void installQtMessageHandler();
// Whether a Qt log category belongs in the journal at all. Qt's platform
// plugins (`qt.qpa.*`: xcb, wayland, ...) narrate the display server, not
// the application: the Wayland one, for instance, repeats a warning about
// its text-input focus for every dialog the user opens, which is a line the
// user can neither read nor act on. Those keep going to stderr, where a
// developer looks for them; everything the application itself logs — its
// own categories, and a bare qCWarning — still lands in the journal.
static bool journalsQtCategory(const QString& category);
signals:
// The journal changed on disk and a fresh copy of its content is available.
void fileUpdated();