* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
-#ifndef _LOGGER_H_
-#define _LOGGER_H_
+#ifndef LOGGER_H
+#define LOGGER_H
#include "types.h"
#include <QTextStream>
class Logger {
- public:
- enum LogLevel {
- DebugLevel,
- InfoLevel,
- WarningLevel,
- ErrorLevel
- };
-
- inline Logger(LogLevel level) : stream(new Stream(level)) {}
- ~Logger();
-
- inline Logger &operator<<(const char* t) { stream->internalStream << QString::fromAscii(t); return *this; }
- inline Logger &operator<<(QChar t) { stream->internalStream << t; return *this; }
- inline Logger &operator<<(bool t) { stream->internalStream << (t ? "true" : "false"); return *this; }
- inline Logger &operator<<(char t) { stream->internalStream << t; return *this; }
- inline Logger &operator<<(signed short t) { stream->internalStream << t; return *this; }
- inline Logger &operator<<(unsigned short t) { stream->internalStream << t; return *this; }
- inline Logger &operator<<(signed int t) { stream->internalStream << t; return *this; }
- inline Logger &operator<<(unsigned int t) { stream->internalStream << t; return *this; }
- inline Logger &operator<<(signed long t) { stream->internalStream << t; return *this; }
- inline Logger &operator<<(unsigned long t) { stream->internalStream << t; return *this; }
- inline Logger &operator<<(qint64 t) { stream->internalStream << QString::number(t); return *this; }
- inline Logger &operator<<(quint64 t) { stream->internalStream << QString::number(t); return *this; }
- inline Logger &operator<<(float t) { stream->internalStream << t; return *this; }
- inline Logger &operator<<(double t) { stream->internalStream << t; return *this; }
- inline Logger &operator<<(const QString & t) { stream->internalStream << t; return *this; }
- inline Logger &operator<<(const QLatin1String &t) { stream->internalStream << t.latin1(); return *this; }
- inline Logger &operator<<(const QByteArray & t) { stream->internalStream << t ; return *this; }
- inline Logger &operator<<(const void * t) { stream->internalStream << t; return *this; }
- inline Logger &operator<<(const QStringList & t) { stream->internalStream << t.join(" "); return *this; }
- inline Logger &operator<<(const BufferId & t) { stream->internalStream << QVariant::fromValue(t).toInt(); return *this; }
- inline Logger &operator<<(const NetworkId & t) { stream->internalStream << QVariant::fromValue(t).toInt(); return *this; }
- inline Logger &operator<<(const UserId & t) { stream->internalStream << QVariant::fromValue(t).toInt(); return *this; }
- inline Logger &operator<<(const MsgId & t) { stream->internalStream << QVariant::fromValue(t).toInt(); return *this; }
- inline Logger &operator<<(const IdentityId & t) { stream->internalStream << QVariant::fromValue(t).toInt(); return *this; }
- inline Logger &operator<<(const AccountId & t) { stream->internalStream << QVariant::fromValue(t).toInt(); return *this; }
-
- void log();
- private:
- struct Stream {
- Stream(LogLevel level)
- : internalStream(&buffer, QIODevice::WriteOnly),
- logLevel(level) {}
- QTextStream internalStream;
- QString buffer;
- LogLevel logLevel;
- } *stream;
+public:
+ enum LogLevel {
+ DebugLevel,
+ InfoLevel,
+ WarningLevel,
+ ErrorLevel
+ };
+
+ inline Logger(LogLevel level) : _stream(&_buffer, QIODevice::WriteOnly), _logLevel(level) {}
+ ~Logger();
+
+ static void logMessage(QtMsgType type, const char *msg);
+
+ template<typename T>
+ inline Logger &operator<<(const T &value) { _stream << value << " "; return *this; }
+ inline Logger &operator<<(const QStringList & t) { _stream << t.join(" ") << " "; return *this; }
+ inline Logger &operator<<(bool t) { _stream << (t ? "true" : "false") << " "; return *this; }
+
+private:
+ void log();
+ QTextStream _stream;
+ QString _buffer;
+ LogLevel _logLevel;
};
-inline Logger quDebug() { return Logger(Logger::DebugLevel); }
-inline Logger quInfo() { return Logger(Logger::InfoLevel); }
-inline Logger quWarning() { return Logger(Logger::WarningLevel); }
-inline Logger quError() { return Logger(Logger::ErrorLevel); }
+class quInfo : public Logger {
+public:
+ inline quInfo() : Logger(Logger::InfoLevel) {}
+};
#endif