diff options
| author | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-03-08 19:44:20 +0000 |
|---|---|---|
| committer | Jeremy Lainé <jeremy.laine@m4x.org> | 2010-03-08 19:44:20 +0000 |
| commit | d1765ee554d21cb947eed3fbf1aa9073ff962443 (patch) | |
| tree | 7064c86d355581e8a63fe77d54d6e74bc6580b1e /source | |
| parent | 7ac9d13564742f06d8e82dff6871e54f4a5f260d (diff) | |
| download | qxmpp-d1765ee554d21cb947eed3fbf1aa9073ff962443.tar.gz | |
rework QXmppLogger again
Diffstat (limited to 'source')
| -rw-r--r-- | source/QXmppClient.cpp | 15 | ||||
| -rw-r--r-- | source/QXmppClient.h | 5 | ||||
| -rw-r--r-- | source/QXmppLogger.cpp | 40 | ||||
| -rw-r--r-- | source/QXmppLogger.h | 13 | ||||
| -rw-r--r-- | source/QXmppReconnectionManager.cpp | 2 | ||||
| -rw-r--r-- | source/QXmppStream.cpp | 2 | ||||
| -rw-r--r-- | source/QXmppUtils.cpp | 5 |
7 files changed, 43 insertions, 39 deletions
diff --git a/source/QXmppClient.cpp b/source/QXmppClient.cpp index 7ba994dd..76620139 100644 --- a/source/QXmppClient.cpp +++ b/source/QXmppClient.cpp @@ -38,9 +38,10 @@ /// The default value is 0. QXmppClient::QXmppClient(QObject *parent) - : QObject(parent), m_stream(0), m_clientPrecence(QXmppPresence::Available), + : QObject(parent), m_logger(0), m_stream(0), m_clientPrecence(QXmppPresence::Available), m_reconnectionManager(0) { + m_logger = QXmppLogger::getLogger(); m_stream = new QXmppStream(this); bool check = connect(m_stream, SIGNAL(messageReceived(const QXmppMessage&)), @@ -186,7 +187,7 @@ void QXmppClient::connectToServer(const QString& host, else { qWarning("QXmppClient::connectToServer: Invalid bareJid"); - logger() << QString("Invalid bareJid"); + logger()->debug() << QString("Invalid bareJid"); } } @@ -525,7 +526,13 @@ bool QXmppClient::handleStreamElement(const QDomElement &element) /// Return the QXmppLogger associated with the client. -QXmppLogger &QXmppClient::logger() +QXmppLogger *QXmppClient::logger() { - return *QXmppLogger::getLogger(); + return m_logger; } + +void QXmppClient::setLogger(QXmppLogger *logger) +{ + m_logger = logger; +} + diff --git a/source/QXmppClient.h b/source/QXmppClient.h index 4339535d..f49ac75c 100644 --- a/source/QXmppClient.h +++ b/source/QXmppClient.h @@ -194,8 +194,10 @@ public: QXmppClient::StreamError getXmppStreamError(); + QXmppLogger *logger(); + void setLogger(QXmppLogger *logger); + virtual bool handleStreamElement(const QDomElement &element); - virtual QXmppLogger &logger(); public slots: void sendPacket(const QXmppPacket&); @@ -207,6 +209,7 @@ public slots: void setClientPresence(QXmppPresence::Status::Type statusType); private: + QXmppLogger* m_logger; QXmppStream* m_stream; ///< Pointer to QXmppStream object a wrapper over ///< TCP socket and XMPP protocol QXmppConfiguration m_config; ///< This object provides the configuration diff --git a/source/QXmppLogger.cpp b/source/QXmppLogger.cpp index 2bbf727e..e614cb86 100644 --- a/source/QXmppLogger.cpp +++ b/source/QXmppLogger.cpp @@ -21,6 +21,7 @@ * */ +#include <QDebug> #include <QFile> #include <QTime> @@ -29,13 +30,13 @@ QXmppLogger* QXmppLogger::m_logger = 0; QXmppLogger::QXmppLogger() - : m_loggingType(QXmppLogger::NONE), m_file(0) + : m_loggingType(QXmppLogger::NONE), m_device(0) { } QXmppLogger::~QXmppLogger() { - delete m_file; + delete m_device; } QXmppLogger* QXmppLogger::getLogger() @@ -51,25 +52,27 @@ QXmppLogger* QXmppLogger::getLogger() void QXmppLogger::setLoggingType(QXmppLogger::LoggingType log) { - if (m_file) + if (m_device) { - delete m_file; - m_file = 0; + delete m_device; + m_device = 0; } + + QFile *file = 0; switch(log) { case QXmppLogger::FILE: - m_file = new QFile("QXmppClientLog.log"); - m_file->open(QIODevice::Append); + file = new QFile("QXmppClientLog.log"); + file->open(QIODevice::Append); break; case QXmppLogger::STDOUT: - m_file = new QFile(); - m_file->open(stdout, QIODevice::WriteOnly); + file = new QFile(); + file->open(stdout, QIODevice::WriteOnly); break; case QXmppLogger::NONE: break; } - m_stream.setDevice(m_file); + m_device = file; m_loggingType = log; } @@ -78,20 +81,11 @@ QXmppLogger::LoggingType QXmppLogger::loggingType() return m_loggingType; } -QXmppLogger &QXmppLogger::operator<<(const QByteArray &str) -{ - if (m_loggingType != NONE) - { - m_stream << QTime::currentTime().toString("hh:mm:ss.zzz") << " : "<< - str << "\n\n"; - m_stream.flush(); - } - return *this; -} - -QXmppLogger &QXmppLogger::operator<<(const QString &str) +QDebug QXmppLogger::debug() { - return (*this << str.toLocal8Bit()); + if (m_device) + return QDebug(m_device) << QTime::currentTime().toString("hh:mm:ss.zzz") << ":"; + return QDebug(m_device); } QXmppLogger::LoggingType QXmppLogger::getLoggingType() diff --git a/source/QXmppLogger.h b/source/QXmppLogger.h index 23d15770..271dd389 100644 --- a/source/QXmppLogger.h +++ b/source/QXmppLogger.h @@ -27,7 +27,7 @@ #include <QTextStream> -class QFile; +class QIODevice; /// Singleton class class QXmppLogger @@ -40,24 +40,23 @@ public: STDOUT }; - ~QXmppLogger(); - static QXmppLogger* getLogger(); + QXmppLogger::LoggingType loggingType(); void setLoggingType(QXmppLogger::LoggingType); - QXmppLogger& operator<<(const QByteArray &b); - QXmppLogger& operator<<(const QString &str); + QDebug debug(); // deprecated methods QXmppLogger::LoggingType Q_DECL_DEPRECATED getLoggingType(); private: QXmppLogger(); + ~QXmppLogger(); + static QXmppLogger* m_logger; QXmppLogger::LoggingType m_loggingType; - QFile *m_file; - QTextStream m_stream; + QIODevice *m_device; }; #endif // QXMPPLOGGER_H diff --git a/source/QXmppReconnectionManager.cpp b/source/QXmppReconnectionManager.cpp index 4cb2a838..006b12b9 100644 --- a/source/QXmppReconnectionManager.cpp +++ b/source/QXmppReconnectionManager.cpp @@ -83,7 +83,7 @@ void QXmppReconnectionManager::reconnect() { if(m_client) { - m_client->logger() << QString("QXmppReconnectionManager::reconnect()"); + m_client->logger()->debug() << QString("QXmppReconnectionManager::reconnect()"); emit reconnectingNow(); m_client->connectToServer(m_client->getConfiguration()); } diff --git a/source/QXmppStream.cpp b/source/QXmppStream.cpp index bf4af1f9..7f479574 100644 --- a/source/QXmppStream.cpp +++ b/source/QXmppStream.cpp @@ -242,7 +242,7 @@ void QXmppStream::sendNonSASLAuthQuery( const QString &to ) void QXmppStream::log(const QString &data) { - m_client->logger() << data; + m_client->logger()->debug() << data; } void QXmppStream::parser(const QByteArray& data) diff --git a/source/QXmppUtils.cpp b/source/QXmppUtils.cpp index dbd62bb8..430b34d0 100644 --- a/source/QXmppUtils.cpp +++ b/source/QXmppUtils.cpp @@ -24,6 +24,7 @@ #include "QXmppUtils.h" #include "QXmppLogger.h" +#include <QDebug> #include <QString> #include <QXmlStreamWriter> #include <QByteArray> @@ -118,12 +119,12 @@ void helperToXmlAddTextElement(QXmlStreamWriter* stream, const QString& name, void log(const QString& str) { - *QXmppLogger::getLogger() << str; + QXmppLogger::getLogger()->debug() << str; } void log(const QByteArray& str) { - *QXmppLogger::getLogger() << str; + QXmppLogger::getLogger()->debug() << str; } QString escapeString(const QString& str) |
