Categorized logging in KDE?

Mark markg85 at gmail.com
Sat Oct 12 12:55:32 UTC 2013


On Sat, Oct 12, 2013 at 10:42 AM, David Faure <faure at kde.org> wrote:

> On Wednesday 09 October 2013 15:29:56 Mark wrote:
> > Hi,
> >
> > As you all probably know by now, Qt has included of categorized logging
> [1]
> > as of 5.2.
> > In KDE we've had categorized logging for ages, but while porting to
> > Frameworks we started using the "simple" Qt logging q<Debug, Notice and
> > Warning>.
> >
> > However, we now again have categorized logging from within Qt. That makes
> > me wonder, do we still need to port back to q<Debug, Notice and Warning>
> or
> > are we now going to use the categorized versions: qC<Debug, Notice and
> > Warning>?
>
> The latter, especially in libraries. Feel free to start porting kdelibs to
> that.
>
> Ok, cool.

But i still miss one tiny detail.. How can we toggle logging at runtime by
using for example kdebugdialog?
The example looks like this:

// in a header
Q_DECLARE_LOGGING_CATEGORY(QT_DRIVER_USB)

// in one source file
Q_LOGGING_CATEGORY(QT_DRIVER_USB, "qt.driver.usb")

// usbEntries() will only be called if QT_DRIVER_USB category is enabled
qCDebug(QT_DRIVER_USB) << "devices: " << usbEntries();

It's not even clear to me how to add a new category and enable it with the
above macro examples.
I can get it working if i do this:

QLoggingCategory usbCategory("qt.driver.usb");
usbCategory.setEnabled(QtDebugMsg, true);
qCDebug(usbCategory) << "USB driver logging...";

So that works.. but getting "qCDebug(QT_DRIVER_USB)..." to work is
something i'm still having trouble with.
Still playing with this to get it working.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.kde.org/pipermail/kde-frameworks-devel/attachments/20131012/5ad76fbd/attachment.html>


More information about the Kde-frameworks-devel mailing list