[Development] QLog ( Work on qDebug and friends)

BRM bm_witness at yahoo.com
Tue Feb 14 16:47:35 CET 2012


> From: "kai.koehne at nokia.com" <kai.koehne at nokia.com>
> To: bm_witness at yahoo.com; development at qt-project.org
> Cc: 
> Sent: Tuesday, February 14, 2012 9:31 AM
> Subject: RE: [Development] QLog ( Work on qDebug and friends)
> 
>>  -----Original Message-----
>>  From: development-bounces+kai.koehne=nokia.com at qt-project.org
>>  [mailto:development-bounces+kai.koehne=nokia.com at qt-project.org] On
>>  Behalf Of ext BRM
>>  Sent: Tuesday, February 14, 2012 3:00 PM
>>  To: development at qt-project.org
>>  Subject: Re: [Development] QLog ( Work on qDebug and friends)
>> 
>>  ----- Original Message -----
>> 
>>  > From: "kai.koehne at nokia.com" <kai.koehne at nokia.com>
>>  >>  -----Original Message-----
>>  >>  From: development-bounces+kai.koehne=nokia.com at qt-project.org
>>  >>  [mailto:development-bounces+kai.koehne=nokia.com at qt-project.org]
>>  On
>>  >> Behalf Of Ramsay Lincoln (Nokia-MP/Brisbane)
>>  >>  Sent: Monday, February 13, 2012 1:33 AM
>>  >>  To: development at qt-project.org
>>  >>  Subject: Re: [Development] QLog ( Work on qDebug and friends)
>>  >>
>>  >>  On 02/11/2012 01:44 AM, ext kai.koehne at 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__)
> 
> Nice, though it'll break with
> 
> qDebug() << "Hi there";
> 
> "too few arguments to function bool qLogIsCategory(const char*)"

Except the "Hi there" will be the 'category' part, so it'll be passed to qLogIsCategory(), which should return false and then cause the last else to be followed.

> Also this won't work:
> 
> qDebug("category") << "HI there";
> 
> "expected primary expression before the '<<' token.

Personally, I'd advocate against that any how. I'd much rather see a Category object being pushed via operator<<() instead so that it can be detected and allow things like:

// assume QMessageLoggerCategory(category) is a class
qDebug() << QMessageLoggerCategory("category1") << "message for category1" << QMessageLoggerCategory("category2") << "message for category2";

But that's me.




More information about the Development mailing list