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:
4 files changed
+85
-15
No files matched your search
+25
-14
@@ -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();
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user