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
@@ -5,6 +5,7 @@
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QLoggingCategory>
|
||||
#include <QObject>
|
||||
#include <QSettings>
|
||||
#include <QString>
|
||||
@@ -271,6 +272,43 @@ void testJournalMovesAndRotates() {
|
||||
assert(journal.currentSizeBytes() > before);
|
||||
}
|
||||
|
||||
// Qt's platform plugins narrate the display server, not the application: the
|
||||
// Wayland text-input warning, for one, repeats for every dialog the user opens,
|
||||
// and a journal full of it is unreadable. Those categories stay on stderr; what
|
||||
// the application logs — its own categories, and the "default" one a bare
|
||||
// qCWarning carries — still lands in the journal.
|
||||
void testPlatformChatterStaysOutOfTheJournal() {
|
||||
// The decision itself first, so the test says which side a category is on
|
||||
// even when nothing is written.
|
||||
assert(LogManager::journalsQtCategory(QStringLiteral("default")));
|
||||
assert(LogManager::journalsQtCategory(QStringLiteral("pacmgr.update")));
|
||||
assert(LogManager::journalsQtCategory(QStringLiteral("qt.sql")));
|
||||
assert(!LogManager::journalsQtCategory(QStringLiteral("qt.qpa.wayland.textinput")));
|
||||
assert(!LogManager::journalsQtCategory(QStringLiteral("qt.qpa.xcb")));
|
||||
|
||||
resetSettings();
|
||||
AppSettings& prefs = AppSettings::instance();
|
||||
const QString dir = QDir::homePath() + QStringLiteral("/journal-c");
|
||||
QFile::remove(dir + QStringLiteral("/operations.log"));
|
||||
prefs.setLogDirectory(dir);
|
||||
prefs.setLogMaxBytes(0);
|
||||
|
||||
LogManager::installQtMessageHandler();
|
||||
LogManager& journal = LogManager::instance();
|
||||
|
||||
// An event the application writes, then the warning Qt's Wayland plugin
|
||||
// repeats: the first must be in the journal, the second must not.
|
||||
journal.logEvent(QStringLiteral("ui"), QStringLiteral("mot de passe fourni"));
|
||||
qCWarning(QLoggingCategory("qt.qpa.wayland.textinput"))
|
||||
<< "Trying to disable 0x1 but 0x2 is focused";
|
||||
qCWarning(QLoggingCategory("pacmgr.update")) << "une alerte de l'application";
|
||||
|
||||
const QString content = journal.readFile();
|
||||
assert(content.contains(QStringLiteral("mot de passe fourni")));
|
||||
assert(content.contains(QStringLiteral("une alerte de l'application")));
|
||||
assert(!content.contains(QStringLiteral("Trying to disable")));
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
@@ -299,6 +337,7 @@ int main(int argc, char* argv[]) {
|
||||
testUpdateBlockIsPersistedAndCleared();
|
||||
testAutomaticCheckCanBeTurnedOff();
|
||||
testJournalMovesAndRotates();
|
||||
testPlatformChatterStaysOutOfTheJournal();
|
||||
|
||||
std::cout << "app-settings: all tests passed" << std::endl;
|
||||
return 0;
|
||||
|
||||
Reference in new issue
Block a user