[Development] Work on qDebug and friends - debug areas
joao.abecasis at nokia.com
joao.abecasis at nokia.com
Fri Jan 27 01:36:27 CET 2012
Kai Koehne wrote:
> Olivier Goffart wrote:
> > On Tuesday 24 January 2012 11:03:11 kai.koehne at nokia.com wrote:
> > > + comparing int's is fast
> > > - one central registry needed for debug areas (no go for custom
> > > apps?)
> >
> > May I suggest we use something like qHash("MyModule") And ignore the
> > fact that there are collisions. (you only would loose a bit
> > granularity in rare occasions.)
>
> I guess the KDebug::registerArea David mentioned does pretty much that.
> I researched a bit whether you somehow can do hashing already on compile
> time, but it seems not to be possible even with Cx11 :( If you're doing
> something like qHash you most probably don't want to do it in every
> single qDebug line ...
Some crazy suggestions from me:
1) Use standard literals, c-strings. This can be "enforced" with a macro
that sringifies the argument:
#define DEBUG(AREA) qDoDebug( #AREA , __FILE__, __LINE__)
// ...
DEBUG(Coffee) << "Coffee is ready!";
// ...
The implementation would hash the pointer itself and print string and
pointer the first time around. Once registered and full string logged
the first time an area is seen only the pointer matters as a unique
identifier (different pointers could still map to the same area).
2) Use Q_DECLARE_METATYPE to register your own type and use the type Id
as the int:
namespace LogArea {
class Timer {};
class IO {};
class Coffee {};
}
Q_DECLARE_METATYPE(LogArea::Timer);
Q_DECLARE_METATYPE(LogArea::IO);
Q_DECLARE_METATYPE(LogArea::Coffee);
// ...
DEBUG(LogArea::Coffee) << "Coffee is ready!";
// ...
Cheers,
João
More information about the Development
mailing list