[Development] QLog ( Work on qDebug and friends)

Oswald Buddenhagen oswald.buddenhagen at nokia.com
Tue Feb 7 11:21:32 CET 2012


On Tue, Feb 07, 2012 at 06:54:55AM +0000, ext wolfgang.beck at nokia.com wrote:
> I'm working to integrade category log with QMessageLogger & Co and unfortunatelly we can not use
> qDebg(<category>) << "my message" because there is already a debug(const char *msg, ...) function
> combining with the macro 
> #define qDebug QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).debug.
> 
> So I use a new function and macro:
>     QDebug debug();
>     QDebug debugCategory(const char *msg);
>     QDebug warning();
>     QDebug warningCategory(const char *msg);
>     QDebug critical();
>     QDebug criticalCategory(const char *msg);
>     QDebug fatalCategory(const char *msg);
> 
> #define qDebugCat(category) QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).debugCategory(#category)
> #define qWarningCat(category) QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).warningCategory(#category)
> #define qCriticalCat(category) QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).criticalCategory(#category)
> #define qFatalCat(category) QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).fatalCategory(#category)
> 
> Any problems with this naming conventions???
> 
yes. they suggest that you are getting a category back. a proper verbose
name would be fooWithCategory or possibly categorizedFoo.
the fatal cat certainly has entertainment value, but is not necessarily
good api.
i'd actually suggest going the microsoft route and naming the functions
qFooEx or something similarly undescriptive. then it's clear that it's
"just an overload".

fwiw, the right solution would of course be renaming the existing
qFoo(const char *) to qPrintFoo(const char *) - the overloading always
seemed weird to me anyway (especially as the stream variant works only
with qdebug.h, while the print variant "just works"). unfortunately,
this is not source compatible.



More information about the Development mailing list