[Development] Difficulties using Qt's new categorized logging. How to install filters?

Koehne Kai Kai.Koehne at digia.com
Tue Oct 15 15:59:29 CEST 2013


> -----Original Message-----
> From: Mark [mailto:markg85 at gmail.com]
> 
> Hi Kai,
> 
> Now i finally get how it works! But why is it done this way? It just doesn't
> smell like the Qt way of doing things. Here is an example of how i would've
> expected something like this to work:
> 
> 
> QLoggingCategory newCategory("some.new.category");
> newCategory->setEnabled(QtDebugMsg, true);
> QLoggingCategory::installFilter(newCategory);

Well, for such simple cases setFilterRules() would suffice. The imagined use case for installFilter is if you're e.g. running your own logging framework, and define filter rules by other means than the simple wildcards setFilterRules supports. That is, you don't necessarily know the categories you're interested in in advance. One example could be a filter that , for each new category that appears at runtime, checks whether a similar environment variable is set or not. Or a logging library that defines filters and sinks (file, db ...) and formatting in one central custom configuration file.

> Like that or something alike. So why isn't it done like that?
> You have to agree with me that this looks a lot cleaner and much more "the
> Qt way" then what is currently the situation?

I agree a global function hook is not the nicest API, but it's not without precedence in Qt either: See e.g. http://qt-project.org/doc/qt-5.0/qtcore/qtglobal.html#qInstallMessageHandler , or http://qt-project.org/doc/qt-4.8/qcoreapplication.html#setEventFilter . It's just a very flexible , low level way to implement hooks :) 

Regards

Kai

PS: The filter stuff came in pretty late in the review process, so feedback on it is highly appreciated. I'm even open to remove it for 5.2 if we feel it needs more thought ...



More information about the Development mailing list