PDA

View Full Version : QLoggingCategory question



focusdoit
25th October 2016, 18:12
I wrote a simple program to understand QLoggingCategory class.

I found with the following 2 statements.
QLoggingCategory category("qtCustom.log");
qCDebug(category) << "main a debug message";
The QT Application output pane shows:
qtCustom.log main a debug message

But when I change them to :
QLoggingCategory category("qt.Custom.log");
qCDebug(category) << "main a debug message";
then QT Application output pane shows nothing.

Does anybody know the reason?

ChrisW67
25th October 2016, 21:10
Have you changed/added the corresponding Q_DECLARE_LOGGING_CATEGORY() and Q_LOGGING_CATEGORY() macros?
Have you ensured the category is enabled?

focusdoit
25th October 2016, 22:13
I only changed the string parameter, qt.custom.log, and qtcustom.log

anda_skoa
26th October 2016, 11:27
There could be a logging configuration that disables "qt.*" or "qt.*.log", etc.

This would match the second string, but not the first.

Cheers,
_

focusdoit
26th October 2016, 17:53
the whole code block is :

int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QLoggingCategory::setFilterRules(QStringLiteral("qt.custom.log.debug=false"));
qSetMessagePattern("%{category} %{message}");

Widget w;
QLoggingCategory category("qtCustom.log");
qCDebug(category) << "main a debug message";
w.show();

return a.exec();
}

And I tried to change false to "true", "debug" to "release", "qtCustom.log.debug=false" etc.
but still got same result.

#include "widget.h"
#include "ui_widget.h"

Q_LOGGING_CATEGORY(QT_CUSTOM_LOG, "qt.custom.log")

Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QLoggingCategory custom("construct");
qCDebug(custom) << "Widget initialzation ...";
}

Widget::~Widget()
{
delete ui;
}

focusdoit
26th October 2016, 20:08
I got it, QLoggingCategory::setFilterRules(QStringLiteral("q t.custom.log.debug=false")); should be changed to
QLoggingCategory::setFilterRules(QStringLiteral("q t.custom.log.debug=true"));