summaryrefslogtreecommitdiffstats
path: root/src/corelib/global
diff options
context:
space:
mode:
authorWolfgang Beck <wolfgang.beck@nokia.com>2012-01-16 17:45:23 +1000
committerQt by Nokia <qt-info@nokia.com>2012-04-03 10:45:02 +0200
commit7552d94d31e48a70ea92df9b5235a6e0834d44f5 (patch)
tree674836b16b0e6601ed220f722914e0851e315040 /src/corelib/global
parentf1d2f7cfa0875635a9e2ac788bef7094ac549028 (diff)
Prepare category logging for Qt integration
Change-Id: I0c784a945fe87d7ba52a44f5c7246de1709ae888 Reviewed-by: Lincoln Ramsay <lincoln.ramsay@nokia.com> Reviewed-by: Peter Yard <peter.yard@nokia.com> Reviewed-by: Alex <alex.blasche@nokia.com>
Diffstat (limited to 'src/corelib/global')
-rw-r--r--src/corelib/global/qlogging.cpp26
-rw-r--r--src/corelib/global/qlogging.h14
2 files changed, 25 insertions, 15 deletions
diff --git a/src/corelib/global/qlogging.cpp b/src/corelib/global/qlogging.cpp
index fe19ae631e..afefb11aa1 100644
--- a/src/corelib/global/qlogging.cpp
+++ b/src/corelib/global/qlogging.cpp
@@ -147,9 +147,7 @@ QDebug QMessageLogger::debug()
{
QDebug dbg = QDebug(QtDebugMsg);
QMessageLogContext &ctxt = dbg.stream->context;
- ctxt.file = context.file;
- ctxt.line = context.line;
- ctxt.function = context.function;
+ ctxt.copy(context);
return dbg;
}
@@ -174,9 +172,7 @@ QDebug QMessageLogger::warning()
{
QDebug dbg = QDebug(QtWarningMsg);
QMessageLogContext &ctxt = dbg.stream->context;
- ctxt.file = context.file;
- ctxt.line = context.line;
- ctxt.function = context.function;
+ ctxt.copy(context);
return dbg;
}
#endif
@@ -196,9 +192,7 @@ QDebug QMessageLogger::critical()
{
QDebug dbg = QDebug(QtCriticalMsg);
QMessageLogContext &ctxt = dbg.stream->context;
- ctxt.file = context.file;
- ctxt.line = context.line;
- ctxt.function = context.function;
+ ctxt.copy(context);
return dbg;
}
#endif
@@ -369,6 +363,7 @@ Q_AUTOTEST_EXPORT QByteArray qCleanupFuncinfo(QByteArray info)
}
// tokens as recognized in QT_MESSAGE_PATTERN
+static const char categoryTokenC[] = "%{category}";
static const char typeTokenC[] = "%{type}";
static const char messageTokenC[] = "%{message}";
static const char fileTokenC[] = "%{file}";
@@ -438,7 +433,9 @@ QMessagePattern::QMessagePattern()
// placeholder
if (lexeme == QLatin1String(typeTokenC)) {
tokens[i] = typeTokenC;
- } else if (lexeme == QLatin1String(messageTokenC))
+ } else if (lexeme == QLatin1String(categoryTokenC))
+ tokens[i] = categoryTokenC;
+ else if (lexeme == QLatin1String(messageTokenC))
tokens[i] = messageTokenC;
else if (lexeme == QLatin1String(fileTokenC))
tokens[i] = fileTokenC;
@@ -505,6 +502,8 @@ Q_CORE_EXPORT QByteArray qMessageFormatString(QtMsgType type, const QMessageLogC
const char *token = pattern->tokens[i];
if (token == messageTokenC) {
message.append(str);
+ } else if (token == categoryTokenC) {
+ message.append(context.category);
} else if (token == typeTokenC) {
switch (type) {
case QtDebugMsg: message.append("debug"); break;
@@ -681,4 +680,11 @@ QtMsgHandler qInstallMsgHandler(QtMsgHandler h)
return old;
}
+void QMessageLogContext::copy(const QMessageLogContext &logContext)
+{
+ this->category = logContext.category;
+ this->file = logContext.file;
+ this->line = logContext.line;
+ this->function = logContext.function;
+}
QT_END_NAMESPACE
diff --git a/src/corelib/global/qlogging.h b/src/corelib/global/qlogging.h
index 4de04bdc33..29313bd582 100644
--- a/src/corelib/global/qlogging.h
+++ b/src/corelib/global/qlogging.h
@@ -66,15 +66,17 @@ class QMessageLogContext
{
Q_DISABLE_COPY(QMessageLogContext)
public:
- QMessageLogContext() : version(1), line(0), file(0), function(0) {}
- Q_DECL_CONSTEXPR QMessageLogContext(const char *fileName, int lineNumber,
- const char *functionName)
- : version(1), line(lineNumber), file(fileName), function(functionName) {}
+ QMessageLogContext() : version(1), line(0), file(0), function(0), category(0) {}
+ Q_DECL_CONSTEXPR QMessageLogContext(const char *fileName, int lineNumber, const char *functionName, const char *categoryName)
+ : version(1), line(lineNumber), file(fileName), function(functionName), category(categoryName) {}
+
+ void copy(const QMessageLogContext &logContext);
int version;
int line;
const char *file;
const char *function;
+ const char *category;
private:
friend class QMessageLogger;
@@ -87,7 +89,9 @@ class Q_CORE_EXPORT QMessageLogger
public:
QMessageLogger() : context() {}
Q_DECL_CONSTEXPR QMessageLogger(const char *file, int line, const char *function)
- : context(file, line, function) {}
+ : context(file, line, function, "default") {}
+ Q_DECL_CONSTEXPR QMessageLogger(const char *file, int line, const char *function, const char *category)
+ : context(file, line, function, category) {}
void debug(const char *msg, ...)
#if defined(Q_CC_GNU) && !defined(__INSURE__)