[Development] QLog ( Work on qDebug and friends)

kai.koehne at nokia.com kai.koehne at nokia.com
Tue Feb 7 08:26:53 CET 2012


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