/***************************************************************************
- * Copyright (C) 2005 by the Quassel Project *
+ * Copyright (C) 2005-2016 by the Quassel Project *
* devel@quassel-irc.org *
* *
* This program is free software; you can redistribute it and/or modify *
* 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
-#include "types.h"
-
-#include <QString>
#include <QStringList>
#include <QTextStream>
-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; }
- 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; }
+#if QT_VERSION < 0x050000
+ static void logMessage(QtMsgType type, const char *msg);
+#else
+ static void logMessage(QtMsgType, const QMessageLogContext&, const QString&);
+#endif
+ 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();
- 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