From 62f9a85f798a1fcdc74b0d25d11220bebed557e5 Mon Sep 17 00:00:00 2001 From: Gergely Risko Date: Tue, 8 Sep 2009 15:39:18 +0300 Subject: Logging simplifications and support for everything supported by QDebug(). --- common/logging.cpp | 110 ++--------------------------------------------------- common/logging.h | 36 +++--------------- 2 files changed, 8 insertions(+), 138 deletions(-) (limited to 'common') diff --git a/common/logging.cpp b/common/logging.cpp index de0ac527..72c5b0fb 100644 --- a/common/logging.cpp +++ b/common/logging.cpp @@ -309,11 +309,11 @@ ContextRealLogger::ContextRealLogger(int type, const char *module, const char *f // Add timestamp if (! hideTimestamps && ! vanilla) - *this << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss"); + *this << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss").toLocal8Bit().data(); // Module name if (! vanilla) - *this << QString("[" + QString(module) + "]"); + *this << QString("[" + QString(module) + "]").toLocal8Bit().data(); // Message name switch(type) { @@ -338,7 +338,7 @@ ContextRealLogger::ContextRealLogger(int type, const char *module, const char *f // File, line and function... if (! vanilla) - *this << QString("[" + QString(file) + ":" + QString::number(line) + ":" + QString(func) + "]"); + *this << QString("[" + QString(file) + ":" + QString::number(line) + ":" + QString(func) + "]").toLocal8Bit().data(); } bool ContextRealLogger::shouldPrint() @@ -419,107 +419,3 @@ ContextRealLogger::~ContextRealLogger() setDevice(NULL); } - -/// Standard QTextStream operators. Automatically adds whitespace. -ContextRealLogger& ContextRealLogger::operator<< (QChar v) -{ - QTextStream::operator<<(v); - QTextStream::operator<<(' '); - return *this; -} - -/// Standard QTextStream operators. Automatically adds whitespace. -ContextRealLogger& ContextRealLogger::operator<< (signed short v) -{ - QTextStream::operator<<(v); - QTextStream::operator<<(' '); - return *this; -} - -/// Standard QTextStream operators. Automatically adds whitespace. -ContextRealLogger& ContextRealLogger::operator<< (unsigned short v) -{ - QTextStream::operator<<(v); - QTextStream::operator<<(' '); - return *this; -} - -/// Standard QTextStream operators. Automatically adds whitespace. -ContextRealLogger& ContextRealLogger::operator<< (signed int v) -{ - QTextStream::operator<<(v); - QTextStream::operator<<(' '); - return *this; -} - -/// Standard QTextStream operators. Automatically adds whitespace. -ContextRealLogger& ContextRealLogger::operator<< (unsigned int v) -{ - QTextStream::operator<<(v); - QTextStream::operator<<(' '); - return *this; -} - -/// Standard QTextStream operators. Automatically adds whitespace. -ContextRealLogger& ContextRealLogger::operator<< (signed long v) -{ - QTextStream::operator<<(v); - QTextStream::operator<<(' '); - return *this; -} - -/// Standard QTextStream operators. Automatically adds whitespace. -ContextRealLogger& ContextRealLogger::operator<< (unsigned long v) -{ - QTextStream::operator<<(v); - QTextStream::operator<<(' '); - return *this; -} - -/// Standard QTextStream operators. Automatically adds whitespace. -ContextRealLogger& ContextRealLogger::operator<< (float v) -{ - QTextStream::operator<<(v); - QTextStream::operator<<(' '); - return *this; -} - -/// Standard QTextStream operators. Automatically adds whitespace. -ContextRealLogger& ContextRealLogger::operator<< (double v) -{ - QTextStream::operator<<(v); - QTextStream::operator<<(' '); - return *this; -} - -/// Standard QTextStream operators. Automatically adds whitespace. -ContextRealLogger& ContextRealLogger::operator<< (void *v) -{ - QTextStream::operator<<(v); - QTextStream::operator<<(' '); - return *this; -} - -/// Standard QTextStream operators. Automatically adds whitespace. -ContextRealLogger& ContextRealLogger::operator<< (const QString &v) -{ - QTextStream::operator<<(v); - QTextStream::operator<<(' '); - return *this; -} - -/// Standard QTextStream operators. Automatically adds whitespace. -ContextRealLogger& ContextRealLogger::operator<< (const char *v) -{ - QTextStream::operator<<(v); - QTextStream::operator<<(' '); - return *this; -} - -/// Standard QTextStream operators. Automatically adds whitespace. -ContextRealLogger& ContextRealLogger::operator<< (char v) -{ - QTextStream::operator<<(v); - QTextStream::operator<<(' '); - return *this; -} diff --git a/common/logging.h b/common/logging.h index 65a5cc16..23be7b15 100644 --- a/common/logging.h +++ b/common/logging.h @@ -27,7 +27,6 @@ #include #include #include -#include #include #define CONTEXT_LOG_MSG_TYPE_TEST 1 @@ -72,23 +71,12 @@ public: ContextRealLogger &operator<< (const ContextFeature&); - virtual ContextRealLogger &operator<< (QChar); - virtual ContextRealLogger &operator<< (signed short); - virtual ContextRealLogger &operator<< (unsigned short); - virtual ContextRealLogger &operator<< (signed int); - virtual ContextRealLogger &operator<< (unsigned int); - virtual ContextRealLogger &operator<< (signed long); - virtual ContextRealLogger &operator<< (unsigned long); - virtual ContextRealLogger &operator<< (float); - virtual ContextRealLogger &operator<< (double); - virtual ContextRealLogger &operator<< (void *); - virtual ContextRealLogger &operator<< (const QString&); - virtual ContextRealLogger &operator<< (const char *); - virtual ContextRealLogger &operator<< (char); - template ContextRealLogger &operator<< (const QSet& set) +// ContextRealLogger &operator<< (const char *str); + + template ContextRealLogger &operator<< (const T& qSomething) { QString out; - QDebug(&out) << set; + QDebug(&out) << qSomething; QTextStream::operator<<(out); return *this; } @@ -122,21 +110,7 @@ public: inline ContextZeroLogger() {} /* Stubby ops */ - inline ContextZeroLogger &operator<< (QChar) { return *this;} ///< Does nothing. - inline ContextZeroLogger &operator<< (char) { return *this;} ///< Does nothing. - inline ContextZeroLogger &operator<< (signed short) { return *this;} ///< Does nothing. - inline ContextZeroLogger &operator<< (unsigned short) { return *this;} ///< Does nothing. - inline ContextZeroLogger &operator<< (signed int) { return *this;} ///< Does nothing. - inline ContextZeroLogger &operator<< (unsigned int) { return *this;} ///< Does nothing. - inline ContextZeroLogger &operator<< (signed long) { return *this;} ///< Does nothing. - inline ContextZeroLogger &operator<< (unsigned long) { return *this;} ///< Does nothing. - inline ContextZeroLogger &operator<< (float) { return *this;} ///< Does nothing. - inline ContextZeroLogger &operator<< (double) { return *this;} ///< Does nothing. - inline ContextZeroLogger &operator<< (const char *) { return *this;} ///< Does nothing. - inline ContextZeroLogger &operator<< (const QString&) { return *this;} ///< Does nothing. - inline ContextZeroLogger &operator<< (void *) { return *this;} ///< Does nothing. - inline ContextZeroLogger &operator<< (const ContextFeature&) { return *this;} ///< Does nothing. - template inline ContextZeroLogger &operator<< (const QSet&) { return *this;} ///< Does nothing. + template inline ContextZeroLogger &operator<< (const T&) { return *this;} ///< Does nothing. }; /* Macro defs */ -- cgit v1.2.3