How do I enable Qt logging for an example?
-
I wanted to take a closer look at the widgets/gestures/imagegestures example. For that, I'd like to enable the logging (qCDebug...) contained within the example. I miraculously fail to do so...
- I have no idea where to expect output. Application output? General Messages? A file?
- According to the description of Q_LOGGING_CATEGORY, "By default, all message types are enabled." Although I do not find any code within the example to disable the created category, I do find any output
- A description in main.cpp indicated that I would have to enable logging for the category ("qt.examples.imagegestures.debug=true") for it to work. I tried to create a qtlogging.ini file in my application's start folder. My ini files looks as follows:
[Rules] qt.examples.imagegestures.debug=trueI've seen that there are ways to configure logging categories globally using e.g. an environment variable. But as someone who manages dozens of projects, turning on and off logging categories at a system-global level just doesn't make any sense. I want to configure logging for one application only.
EDIT: Enabling the logging via QT_LOGGING_RULES env variable works. But as mentioned, having one global point for configuring logging rules is a bit tedious with multiple executables to test.
-
I wanted to take a closer look at the widgets/gestures/imagegestures example. For that, I'd like to enable the logging (qCDebug...) contained within the example. I miraculously fail to do so...
- I have no idea where to expect output. Application output? General Messages? A file?
- According to the description of Q_LOGGING_CATEGORY, "By default, all message types are enabled." Although I do not find any code within the example to disable the created category, I do find any output
- A description in main.cpp indicated that I would have to enable logging for the category ("qt.examples.imagegestures.debug=true") for it to work. I tried to create a qtlogging.ini file in my application's start folder. My ini files looks as follows:
[Rules] qt.examples.imagegestures.debug=trueI've seen that there are ways to configure logging categories globally using e.g. an environment variable. But as someone who manages dozens of projects, turning on and off logging categories at a system-global level just doesn't make any sense. I want to configure logging for one application only.
EDIT: Enabling the logging via QT_LOGGING_RULES env variable works. But as mentioned, having one global point for configuring logging rules is a bit tedious with multiple executables to test.
Hi @Asperamanca,
please read https://www.qt.io/blog/2014/03/11/qt-weekly-1-categorized-logging for an introduction.
I have no idea where to expect output. Application output? General Messages? A file?
Categorized logging works the same way as the classic QDebug/QWarning/...: By default, it prints to the console
According to the description of Q_LOGGING_CATEGORY, "By default, all message types are enabled."
You will need to look into the code to be sure. It may enable only critical categories.
I tried to create a qtlogging.ini file in my application's start folder.
No, that one goes to
~/.config/QtProject/qtlogging.ini(so it is global for all apps).But as someone who manages dozens of projects, turning on and off logging categories at a system-global level just doesn't make any sense.
Well you can control everything from your code, so invent whatever mechanism you like :)
Regards