[Development] Let's get rid of qDebug/qWarning/qCritical!

Koehne Kai Kai.Koehne at digia.com
Wed Jan 8 09:35:24 CET 2014


Hi,

Do I have your attention? Good :)

Since Qt 5.2 we support categorized logging in Qt, and the next logical step is to also take it into good use inside the Qt libs. I'd therefore like to propose changing qDebug, qWarning uses in the Qt code base into qCDebug, qCWarning , ...

Just for the record, here are the advantages:
- individual categories/levels can be enabled / disabled at runtime, so there's no need any more to recompile Qt to e.g. get debug output for some area [1]
- we unify the different ways to let Qt be chatty (environment variables, #ifdef's, enum { debug } ...) into one, discoverable, approach
- the categories are printed by default before the message, allowing you to filter output per area
- you don't have to worry anymore whether it's 'right' to use #include <QDebug> in a release build ;)


Here is my proposal:
- Modules declare/define their categories in a central place, e.g. q[module]_logging_p.h/q[module]_logging.cpp
- Category names follow the qt.[module].[area].[subarea] pattern (area, subarea are optional)
- Category ID's follow the qtModuleAreaSubarea pattern (e.g. qtCoreIo, though this is still under discussion, see patch)
- Current #ifdef's, environment variables etc should be replaced with an unconditional qCDebug/qCWarning/qCCritical


As a blueprint I've started  a patch for a 'qt.core.io' category:

https://codereview.qt-project.org/#change,74862,patchset=1

If that gets reviewed/accepted I'll probably continue with some other areas, but it's certainly a lot of tedious work in qtbase, so I'd like to encourage everyone to participate :)

What do you think?

Kai

[1]: We don't have a generic way to configure this at runtime _yet_, but that's on my agenda for 5.3, too

-- 
   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, Tuula Haataja
   Registergericht: Amtsgericht Charlottenburg, HRB 144331 B




More information about the Development mailing list