[Interest] Why does the QtLogging message not include type (e.g. WARNING)?

Axel Spoerl axel.spoerl at qt.io
Sun Dec 10 15:10:50 CET 2023


Hi Thomas,

the default message handler indeed prints only the message text.
I think, what you need can be implemented by installing a custom message handler as documented here<https://doc.qt.io/qt-6/qtlogging.html#details>.
The message handler receives a QtMsgType<https://doc.qt.io/qt-5/qtglobal.html#QtMsgType-enum> argument, as well as a message context<https://doc.qt.io/qt-6/qmessagelogcontext.html> and the actual message string.

Cheers
Axel
QMessageLogContext Class | Qt Core 6.6.1<https://doc.qt.io/qt-6/qmessagelogcontext.html>
The QMessageLogContext class provides additional information about a log message.
doc.qt.io


________________________________
Von: Interest <interest-bounces at qt-project.org> im Auftrag von Thomas Larsen Wessel <mrvelle at gmail.com>
Gesendet: Sonntag, 10. Dezember 2023 14:03
An: Interest at qt-project.org <Interest at qt-project.org>
Betreff: [Interest] Why does the QtLogging message not include type (e.g. WARNING)?

The documentation (https://doc.qt.io/qt-6/qtlogging.html) states:

    The default pattern is %{if-category}%{category}: %{endif}%{message}

1) In my limited experience most or all logging architectures print the type (aka. severity or criticality, e.g. warning, debug, info, etc.) by default.

2) And in my personal opinion it should be default to print this, since the severity is often just as important as the message itself, when the goal is to leave the user / log reader informed.

Is there a good reason why the severity is left out of the default format?

My current situation and motivation for writing:

I have a number of Python scripts that rely on PyQGIS, which relies on Qt. They are part of a small software package that is distributed to a number of machines. Each of these scripts occasionally produce log messages via QtLogging, and they are all printed without any context (unless I set them up differently). Its not my code that calls QtWarning, etc., they are called from either QGIS or Qt.

Here is an example.

    QStandardPaths: wrong permissions on runtime directory /run/user/1000/, 0755 instead of 0700

When someone sees this warning, they don't know if this is an error or warning. They don't know if its severe enough that they should do something or just ignore this. IMHO there is no doubt it should be prefixed with "Warning", "WARN" or similar.

So now I set a custom format in each of my scripts. That works of course. But IMHO it would make a whole lot of sense if the default format was changed to include the severity :)

Sincerely
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20231210/45548c7c/attachment.htm>


More information about the Interest mailing list