[Development] QLog ( Work on qDebug and friends)
wolfgang.beck at nokia.com
wolfgang.beck at nokia.com
Thu Feb 9 08:10:39 CET 2012
Hi Kai,
I think this was a very good idea so I've tried it but I've run into one important problem.
If I use this trick I have to call the overloaded function in QMessageLogger:
e.g.
1. void debug(QMessageCategory category, const char *format, ...);
and
2. QDebug debug(QMessageCategory category);
The first function is ok but the 2. one needs to return a QDebug object.
In this case I have to do a lots of overhead e.g. function call and creating object after I can check if the category should be logged or not.
So better having a other named macro which I can do
#define qLog(category) \
If(!logging_enable); \
Else QMessageCategory(....).debug()
Cheers,
WB
-----Original Message-----
From: Koehne Kai (Nokia-MP/Berlin)
Sent: Tuesday, February 07, 2012 5:27 PM
To: Beck Wolfgang (Nokia-MP/Brisbane); development at qt-project.org
Subject: RE: QLog ( Work on qDebug and friends)
Hi Wolfgang,
how about making the category a distinct type instead?
struct QMessageCategory {
explicit QMessageCategory(const char *name); };
class QMessageLogger {
void debug(const char *format, ...);
void debug(QMessageCategory category, const char *format, ...); }
...
QDebugCategory debugCategory("MyApp"); // You'll typically do this in one place
...
qDebug(debugCategory, "hi there");
Anyhow, you probably don't want to set the category explicitly for every call in e.g. QtCore, so you can also pass it implicitly via a DEFINE:
class QMessageLogger {
QMessageLogger(const char *file, int line, const char *function, const char *defaultCategory) {
}
}
#define Q_DEBUG_CATEGORY "" // empty default
#define qDebug QMessageLogger(__FILE__, __LINE__, Q_FUNC_INFO, Q_DEBUG_CATEGORY).debug
And QtCore is then compiled with DEFINES+="Q_DEBUG_CATEGORY=QtCore". IMO both approaches are complementary, passing an explicit category would overwrite the Q_DEBUG_CATEGORY define.
Regards
Kai
________________________________________
From: development-bounces+kai.koehne=nokia.com at qt-project.org [development-bounces+kai.koehne=nokia.com at qt-project.org] on behalf of Beck Wolfgang (Nokia-MP/Brisbane)
Sent: Tuesday, February 07, 2012 7:54 AM
To: development at qt-project.org
Subject: [Development] QLog ( Work on qDebug and friends)
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???
Cheers,
WB
_______________________________________________
Development mailing list
Development at qt-project.org
http://lists.qt-project.org/mailman/listinfo/development
More information about the Development
mailing list