----- Original Message -----

> From: "kai.koe...@nokia.com" <kai.koe...@nokia.com>
>>  -----Original Message-----
>>  From: development-bounces+kai.koehne=nokia....@qt-project.org
>>  [mailto:development-bounces+kai.koehne=nokia....@qt-project.org] On
>>  Behalf Of Ramsay Lincoln (Nokia-MP/Brisbane)
>>  Sent: Monday, February 13, 2012 1:33 AM
>>  To: development@qt-project.org
>>  Subject: Re: [Development] QLog ( Work on qDebug and friends)
>> 
>>  On 02/11/2012 01:44 AM, ext kai.koe...@nokia.com wrote:
>>  > However, adding yet another 'keyword' to the framework has a 
> price,
>>  > especially since the difference between
>>  > 'qDebug(QMessageLogContext("MyCategory"))'<< 
> and a
>>  > 'qLog("MyCategory")<< ' is subtle.
>> 
>>  We tried that but while this difference is subtle to the eye, it's a
>>  huge difference to the implementation.
>> 
>>  qDebug is currently an argument-less macro that expands to the name of a
>>  function. Before message logging it was just a plain old function.
>>  Overloading means that qDebug("message") and qDebug() << 
> "message"
>>  both
>>  work.
>> 
>>  Since we can't have a macro func with 0, 1 or many arguments, we can
>>  only add a new overload for qDebug(category) << "message" 
> but if we do
>>  this, there is nowhere to put the "do nothing quickly" logic.
> 
> 
> Just wanted to point out that there are variadic macros: 
> http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html
> 
> #define qCategoryDebug(category, ...) if (isLogEnabled(category)) 
> QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO).debug(__VA_ARGS__)
> 
> Seems to work with at least gcc4.2.1 and Visual studio 2010.
> 
> But that doesn't help with the fact that we can't differentiate between 
> 'qDebug()', 'qDebug("Hello world")', and 
> 'qDebug(MyCategory)' on the macro level.


That depends on implementation. It does allow you take all those args and pass 
them over to other function easily.
And if all categories have to be registered, then you can add a check against 
the registration for it:

..
qLogRegisterCategory("my category");
...
qDebug("my category",...");
...
qDebug(...);
...

#define qDebug(category,...) \
    if (qLogIsCategory(category))    \
        if (qIsLogEnabled(category))   \
            QMessageLogger(__FILE,__LINE__, Q_FUNC_INFO, 
category).debug(__VAR__ARGS__)    \
        else {} \
    else QMessageLogger(__FILE,__LINE__, 
Q_FUNC_INFO).debug(category,##__VAR__ARGS__)

Ben
_______________________________________________
Development mailing list
Development@qt-project.org
http://lists.qt-project.org/mailman/listinfo/development

Reply via email to