[Development] QLog ( Work on qDebug and friends)

kai.koehne at nokia.com kai.koehne at nokia.com
Tue Feb 14 11:22:16 CET 2012



--
Kai Koehne
Senior Software Engineer
Nokia, Mobile Phones
 
Nokia gate5 GmbH
Firmensitz: Invalidenstr. 117, 10115 Berlin, Germany
Registergericht: Amtsgericht Charlottenburg, Berlin: HRB 106443 B
Umsatzsteueridentifikationsnummer: DE 812 845 193
Geschäftsführer: Dr. Michael Halbherr, Karim Tähtivuori


> -----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.

> Expanding to this is always going to be slow:
> func(category) << "args" << expensive();
> 
> We need to expand to this to be fast:
> if (do_nothing) /*NOP*/; else func(category) << "args" << expensive();
> 
> Thus we cannot overload qDebug.
> 
> qLog is just a name. It's the name this code had when it was in Qtopia
> but it's hardly important if it keeps this name. It would be nice to
> focus on the implementation of the feature to make sure it is sound
> before we worry overly much about what to call it :)

Sure, but names still matter for a public API .

Here's another idea:


// in qlogging.h
void qMessageLogEnabled(const char *area)
#define QMessageArea(area) if (qMessageLogEnabled(area)) QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, area)


Usage would be e.g.

QMessageArea("MyArea").debug() << expensiveFunc();
QMessageArea("MyArea").warning("%s", expensiveFunc());

Regards

Kai

> --
> Lincoln Ramsay - Senior Software Engineer
> Qt Development Frameworks, Nokia - http://qt.nokia.com/
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development



More information about the Development mailing list