X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Flogger.h;h=f5a6ff59af12b2864ab4bb66027707f75a5b26a9;hp=708801adeb1fde1c5add60d1e696c91fb1bc1747;hb=0679f0aa992e4d0d0aab2ebe08e17544150fbc55;hpb=99b15ffe7d25b4574f6a85ba394d9514d8b6248a diff --git a/src/common/logger.h b/src/common/logger.h index 708801ad..f5a6ff59 100644 --- a/src/common/logger.h +++ b/src/common/logger.h @@ -36,50 +36,38 @@ class Logger { ErrorLevel }; - inline Logger(LogLevel level) : _stream(new Stream(level)) {} + inline Logger(LogLevel level) : _stream(&_buffer, QIODevice::WriteOnly), _logLevel(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; } + template + 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; } - void log(); private: - struct Stream { - Stream(LogLevel level) - : internalStream(&buffer, QIODevice::WriteOnly), - logLevel(level) {} - QTextStream internalStream; - QString buffer; - LogLevel logLevel; - } *_stream; + void log(); + QTextStream _stream; + QString _buffer; + LogLevel _logLevel; +}; + +class quDebug : public Logger { + public: + inline quDebug() : Logger(Logger::DebugLevel) {} +}; + +class quInfo : public Logger { + public: + inline quInfo() : Logger(Logger::InfoLevel) {} }; -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 quWarning : public Logger { + public: + inline quWarning() : Logger(Logger::WarningLevel) {} +}; +class quError : public Logger { + public: + inline quError() : Logger(Logger::ErrorLevel) {} +}; #endif