Capture specific logging output into a QString
-
wrote on 7 May 2021, 12:59 last edited by
I enabled the following logging category to get some basic information about the scenegraph setup:
`QLoggingCategory::setFilterRules("qt.scenegraph.general=true");
This gives me an output likeqt.scenegraph.general: opengl texture atlas dimensions: 512x512 qt.scenegraph.general: R/G/B/A Buffers: 8 8 8 8 qt.scenegraph.general: Depth Buffer: 24 qt.scenegraph.general: Stencil Buffer: 8 qt.scenegraph.general: Samples: 0 qt.scenegraph.general: GL_VENDOR: Google Inc. qt.scenegraph.general: GL_RENDERER: ANGLE (Intel(R) UHD Graphics 630 Direct3D11 vs_5_0 ps_5_0) qt.scenegraph.general: GL_VERSION: OpenGL ES 2.0 (ANGLE 2.1.0.57ea533f79a7) ...
I'd like to redirect this output to a string, so I can add it to a diagnosis information file. However, the only way I know so far is to use qInstallMessageHandler, which would capture other debug messages as well.
How can I selectively capture the scenegraph info, but not other debug messages?
-
I enabled the following logging category to get some basic information about the scenegraph setup:
`QLoggingCategory::setFilterRules("qt.scenegraph.general=true");
This gives me an output likeqt.scenegraph.general: opengl texture atlas dimensions: 512x512 qt.scenegraph.general: R/G/B/A Buffers: 8 8 8 8 qt.scenegraph.general: Depth Buffer: 24 qt.scenegraph.general: Stencil Buffer: 8 qt.scenegraph.general: Samples: 0 qt.scenegraph.general: GL_VENDOR: Google Inc. qt.scenegraph.general: GL_RENDERER: ANGLE (Intel(R) UHD Graphics 630 Direct3D11 vs_5_0 ps_5_0) qt.scenegraph.general: GL_VERSION: OpenGL ES 2.0 (ANGLE 2.1.0.57ea533f79a7) ...
I'd like to redirect this output to a string, so I can add it to a diagnosis information file. However, the only way I know so far is to use qInstallMessageHandler, which would capture other debug messages as well.
How can I selectively capture the scenegraph info, but not other debug messages?
wrote on 7 May 2021, 13:50 last edited by@Asperamanca
So far as I know: yes you useqInstallMessageHandler
, use theQMessageLogContext
to check the category name, do what you want with your category, call the old message handler for other stuff. -
@Asperamanca
So far as I know: yes you useqInstallMessageHandler
, use theQMessageLogContext
to check the category name, do what you want with your category, call the old message handler for other stuff.wrote on 10 May 2021, 06:47 last edited by@JonB said in Capture specific logging output into a QString:
QMessageLogContext
According to Qt docs, QMessageLogContext does not have a public interface, and may only provide information in debug builds.
-
@JonB said in Capture specific logging output into a QString:
QMessageLogContext
According to Qt docs, QMessageLogContext does not have a public interface, and may only provide information in debug builds.
wrote on 10 May 2021, 08:12 last edited by@Asperamanca
I did not test/look into it further, but I saw e.g. https://stackoverflow.com/questions/29646942/qmessagelogcontexts-fields-like-file-function-line-empty-or-zerovoid action(QtMsgType type, const QMessageLogContext &context, const QString &msg) { ts << context.file << ":" << context.line << ":" << context.function << ": " << msg << endl; }
so it seems to be accessing
QMessageLogContext
fields. The reply there talks about debug/release builds.Your documentation link is https://doc.qt.io/qt-5/qmessagelogcontext.html. But if you look at, say, https://doc-snapshots.qt.io/qt5-5.12/qmessagelogcontext.html you see the various fields described, including
const char *category
. That's all I know!
1/4