X-Git-Url: https://git.quassel-irc.org/?p=quassel.git;a=blobdiff_plain;f=src%2Fcommon%2Flogger.h;h=ea5b01be57eee013e6295b3a727a0627ce62aeb7;hp=f49d270da7aea5a59cc3530b45a17c6ca2a3b9db;hb=e3c42d072b2b8f39c8c9ea44dfc3bded87ae43b0;hpb=6b75ac568098c17de5f0a98ce0d96781b86e98b3 diff --git a/src/common/logger.h b/src/common/logger.h index f49d270d..ea5b01be 100644 --- a/src/common/logger.h +++ b/src/common/logger.h @@ -1,5 +1,5 @@ /*************************************************************************** - * Copyright (C) 2005 by the Quassel Project * + * Copyright (C) 2005-2013 by the Quassel Project * * devel@quassel-irc.org * * * * This program is free software; you can redistribute it and/or modify * @@ -15,61 +15,58 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * ***************************************************************************/ -#ifndef _LOGGER_H_ -#define _LOGGER_H_ +#ifndef LOGGER_H +#define LOGGER_H -#include +#include #include -class Logger { - public: - enum LogLevel { - DebugLevel, - InfoLevel, - WarningLevel, - ErrorLevel - }; +#include "quassel.h" +#include "types.h" - inline Logger(LogLevel level) : stream(new Stream(level)) {} +class Logger +{ +public: + inline Logger(Quassel::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; } + static void logMessage(QtMsgType type, const char *msg); + 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; } + +private: void log(); - private: - struct Stream { - Stream(LogLevel level) - : internalStream(&buffer, QIODevice::WriteOnly), - logLevel(level) {} - QTextStream internalStream; - QString buffer; - LogLevel logLevel; - } *stream; + QTextStream _stream; + QString _buffer; + Quassel::LogLevel _logLevel; +}; + + +class quInfo : public Logger +{ +public: + inline quInfo() : Logger(Quassel::InfoLevel) {} +}; + + +class quWarning : public Logger +{ +public: + inline quWarning() : Logger(Quassel::WarningLevel) {} +}; + + +class quError : public Logger +{ +public: + inline quError() : Logger(Quassel::ErrorLevel) {} }; -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); } #endif