On Tue, Oct 15, 2013 at 10:10 AM, Koehne Kai <kai.koe...@digia.com> wrote: > >> -----Original Message----- >> From: Mark [mailto:mark...@gmail.com] >> Sent: Monday, October 14, 2013 5:40 PM >> To: Koehne Kai >> Cc: development@qt-project.org >> Subject: Re: [Development] Difficulties using Qt's new categorized logging. >> How to install filters? >> [...] >> Hi Kai, >> >> Thank you very much for your explanation! Would you also be able to >> provide an example for installFilter? Since that is the one where i can't >> figure >> out how it's supposed to work. > > Sure. > > So what you can do is define your own category filter: > > QLoggingCategory::CategoryFilter oldCategoryFilter; > > void myCategoryFilter(QLoggingCategory *category) > { > if (qstrcmp(category->categoryName(), "qt.driver.usb") == 0) { > category->setEnabled(QtDebugMsg, true); > } else { > // let the default filter decide based on text rules > *oldCategoryFilter(category); > } > } > > And install it: > > oldCategoryFilter = QLoggingCategory::installFilter(myCategoryFilter); > > > inside installFilter() myCategoryFilter will be called for every > QLoggingCategory object already available. It will also be called whenever a > new QLoggingCategory object is created, and must be reentrant (might be > called from multiple threads concurrently). > > > For this specific example you'd be arguably better of just defining a rule by > setFilterRules. installFilter is mainly useful if you're e.g. defining your > own logging framework, and say enable/disable categories based on some > configuration coming from a file, or network ... . It can also be used to > e.g. log all categories that are created during an application run :) > > I'm currently trying to improve the documentation based on your questions, > please feel free to review: > > https://codereview.qt-project.org/#change,68114 > > Regards > > Kai > > -- > Kai Köhne, Senior Software Engineer - Digia, Qt > Digia Germany GmbH, Rudower Chaussee 13, D-12489 Berlin > Geschäftsführer: Mika Pälsi, Juha Varelius, Anja Wasenius > Sitz der Gesellschaft: Berlin. USt-IdNr: DE 286 306 868 > Registergericht: Amtsgericht Charlottenburg, HRB 144331 B
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); 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? _______________________________________________ Development mailing list Development@qt-project.org http://lists.qt-project.org/mailman/listinfo/development