[Development] Work on qDebug and friends - debug areas

David Faure david.faure at kdab.com
Tue Jan 24 16:01:57 CET 2012


On Tuesday 24 January 2012 11:03:11 kai.koehne at nokia.com wrote:
> KDE & kDebug
> 
> Here debug categories are basically ints, which have to be registered
> 'kdelibs/kdecore/kdebug.areas'. You can pass your specific as an argument
> to kDebug(..) et al., but usually you just set a define
> (KDE_DEFAULT_DEBUG_AREA).
> 
> + comparing int's is fast
> - one central registry needed for debug areas (no go for custom apps?)

It goes further than that. This was the initial situation.
Then I added registerDynamicArea(), which allows custom apps to get an int 
value at runtime, for a given piece of free text describing an area.

This is then written into a config file so that a gui tool (kdebugdialog) can 
find out which free texts are being used, to allow the users to turn it on/off.

The downside is that it requires apps to store that int somewhere and share it 
between the pieces of code that want to use this debug area, which is not 
really convenient. It's easy when it's for a single .cpp file:
static int debugArea() { 
    static int s_area = KDebug::registerArea("kdeui (KConfigDialogManager)"); 
    return s_area;
}
but it's not so easy when this area is needed by multiple .cpp files, then this 
function needs to be declared in some private header, or re-declared with 
"extern".

The upside is that the default area name (kDebug() << ...) is based on the 
application name, so without any efforts from developers, this at least gives a 
way to configure debug output on/off for each application separately.

I am, too, interested in hearing whether there are better solutions to the 
problem.

-- 
David Faure | david.faure at kdab.com | KDE/Qt Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, Sweden (HQ) +46-563-540090
KDAB - Qt Experts - Platform-independent software solutions




More information about the Development mailing list