KCD: use modern logging classes throughout
Needs ReviewPublic

Authored by rjvbb on Aug 18 2017, 8:45 AM.

Details

Reviewers
davidedmundson
ltoscano
Group Reviewers
Frameworks
Summary

This change migrates libkcompactdisc to using modern logging for debugging purposes. It introduces a cd base category since a cd.playlist category existed already.

An additional cd.test category is introduced in the testkcd utility, which also enables logging on all cd categories.

Test Plan

Works as expected.

It appears to be necessary to enable debug output on the cd.test category explicitly, despite setting the QT_LOGGING_RULES env. var, probably because the tKCD instance is created before main() and thus qputenv() are called. I can probably avoid that by using the approach used in the Q_LOGGING_CATEGORY macro but I'm not certain that's worth the trouble?

Diff Detail

Lint
Lint Skipped
Unit
Unit Tests Skipped
Build Status
Buildable 4792
Build 4810: arc lint + arc unit
rjvbb created this revision.Aug 18 2017, 8:45 AM
rjvbb updated this revision to Diff 18325.Aug 18 2017, 8:57 AM

missed 2 instances

rjvbb set the repository for this revision to R349 KCompactDisc Library.Aug 18 2017, 8:58 AM
davidedmundson accepted this revision.Aug 18 2017, 9:31 AM
davidedmundson added a subscriber: davidedmundson.
davidedmundson added inline comments.
src/kcompactdisc_p.cpp
30

there's a trend to use "kf5.frameworkname.subpart" as the category.

This revision is now accepted and ready to land.Aug 18 2017, 9:31 AM
ltoscano requested changes to this revision.Aug 18 2017, 9:31 AM
ltoscano added a subscriber: ltoscano.

I strongly suggest to port to ecm_qt_declare_logging_category for both the old and the new category. This script can automated the process:
https://cgit.kde.org/kde-dev-scripts.git/tree/kf5/convert-qkdebug-to-qcdebug.sh

tests/testkcd.cpp
63

Please don't set this here. It can be controlled at runtime.

68

ditto

This revision now requires changes to proceed.Aug 18 2017, 9:31 AM
ltoscano added inline comments.Aug 18 2017, 9:46 AM
src/kcompactdisc_p.cpp
30

On the other side, this is not a frameworks, but a generic library. I've seen (and pushed) org.kde.<application>[.<subpart>] for applications. What could it be a proper choice here? org.kde.lib.<name>[.<subpart>]? Or simply org.kde.<application>[.<subpart>]?

Some thoughts, I'll update the patch later today.

src/kcompactdisc_p.cpp
30

I see KCalCore does ecm_qt_declare_logging_category(kcalcore_LIB_SRCS HEADER kcalcore_debug.h IDENTIFIER KCALCORE_LOG CATEGORY_NAME org.kde.pim.kcalcore). Note the absence of a lib namespace/whatever.
We could thus use org.kde.kcompactdisc unless there's already a suitable namespace to which it could be added (multimedia, audio, ...).

tests/testkcd.cpp
63

I know it can, and I'd agree for regular applications. This is a test application, its users should not have to go figure out why it produces no output and how to make it print something.

You're right though that QT_LOGGING_RULES can already have been set, I can avoid changing it.

68

And ditto: why would you write an application that's supposed to print test results and NOT enable the printing by default?
(I presume that tests like this would use QPrint() if it existed)

ltoscano added inline comments.Aug 18 2017, 10:40 AM
tests/testkcd.cpp
63

If the output is mandatory, why use a category rule at all, or even logging? (and I know this is a pre-existing problem, but still)

Simply because there's no quick and convenient other way for doing output in Qt, I think. But even then, if QPrint existed you'd be using it in testkcd but most likely not in the library itself and I'd still propose to activate debug output from the library in testkcd.

FWIW, the autotests I've run by hand all seem to generate output that looks suspiciously as if it's generated by the logging classes, and they don't require setting a rule.

rjvbb updated this revision to Diff 18344.Aug 18 2017, 2:30 PM
rjvbb edited edge metadata.

Updated as discussed.

rjvbb set the repository for this revision to R349 KCompactDisc Library.Aug 18 2017, 2:30 PM
dfaure added a subscriber: dfaure.Aug 19 2017, 11:00 PM

Information printed by command-line programs can be done with qInfo(), which is enabled by default, while qDebug() should be disabled by defualt.

rjvbb updated this revision to Diff 18470.Aug 21 2017, 7:22 AM

Using qInfo() in testkcd. Curious that qInfo() is enabled (and isn't disabled by *.info=false in qtlogging.ini) by default but qCInfo() isn't (as you'd expect for "info level" logging).

rjvbb set the repository for this revision to R342 KIO AudioCD.Aug 21 2017, 7:22 AM

For information, qCInfo() is enabled by default if you use the ECM macro for declaring the logging category, or if you pass QtInfoMsg to the Qt macro. But then again, it seems fine with me to use qInfo() in a test program, no need for categorized output for this.

BTW it is *not* curious that isn't qInfo isn't "disabled by *.info=false in qtlogging.ini", it's rather expected since qInfo() is one layer below categorized logging, just like qDebug and qWarning. qtlogging.ini (and the QT_LOGGING_RULES env vars) are about qC*.

tests/testkcd.cpp
64

There's proper API for setting applications defaults, without the need for env vars.

BTW it is *not* curious that isn't qInfo isn't "disabled by *.info=false in qtlogging.ini", it's rather expected since qInfo() is one layer below categorized logging, just like qDebug and qWarning. qtlogging.ini (and the QT_LOGGING_RULES env vars) are about qC*.

I've read that before, yet I notice that qDebug() statements don't print for me if I have *.debug=false in my qtlogging.ini file. Whatever the true reason, I've taken to using qWarning() in my own tests before learning about qInfo() (I have *.warning=true set in qtlogging.ini).

Regardless of that, I meant that AFAIU one typically enables info level messages when even more verbose output than debug output is required. The qC* categories seem to reflect that, IMHO.

There's proper API for setting applications defaults, without the need for env vars.

I only see QLoggingCategory::setFilterRules(), is that what you're referring to? I don't think it'd be proper to use QSettings for a test application, leaving a persistent resource somewhere.

It is rather hard to follow your reasoning...

  1. QtInfoMsg is *between* QtDebugMsg and QtWarningMsg, so it's *not* more verbose than QtDebugMsg, it's less. This is why our default setup (in the ECM macro) is to enable "info and up" (i.e. info, warning, critical) and not debug.
  1. And QLoggingCategory::setFilterRules() has *nothing* to do with QSettings...

Yes QSettings is persistent, but QLoggingCategory::setFilterRules() definitely isn't.

You're right about the first point though, qDebug() is associated to the "default" category of qCDebug(), so it's affected by *.debug=false, I hadn't realized that. Surely it must be the same for qInfo() then -- except that *.info=false would be a very stupid thing to do anyway, IMHO. One *wants* the output from command-line tools.

rjvbb updated this revision to Diff 45221.Nov 10 2018, 8:56 AM

refactored for master/head

rjvbb set the repository for this revision to R349 KCompactDisc Library.Nov 10 2018, 8:56 AM
dfaure added inline comments.Nov 10 2018, 9:39 PM
tests/testkcd.cpp
64

My comment is still valid: why doesn't this use QLoggingCategory::setFilterRules() instead?

68

In my view, qInfo is exactly meant for this use case, the one you call QPrint().