From 372d56eee63dc08b85bd4877226582bef76fc1e4 Mon Sep 17 00:00:00 2001 From: Bas Pape Date: Sun, 21 Apr 2013 00:04:41 +0200 Subject: [PATCH] Logging changed in Qt 5; use QtMessageHandler --- src/client/client.cpp | 24 ++++++++++++++++++++++++ src/client/client.h | 4 ++++ src/common/logger.cpp | 23 +++++++++++++++++++++++ src/common/logger.h | 4 ++++ src/core/coreapplication.cpp | 4 ++++ src/qtui/qtuiapplication.cpp | 4 ++++ 6 files changed, 63 insertions(+) diff --git a/src/client/client.cpp b/src/client/client.cpp index 9ef23efb..3305f5b3 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -646,6 +646,7 @@ void Client::markBufferAsRead(BufferId id) } +#if QT_VERSION < 0x050000 void Client::logMessage(QtMsgType type, const char *msg) { fprintf(stderr, "%s\n", msg); @@ -665,3 +666,26 @@ void Client::logMessage(QtMsgType type, const char *msg) emit instance()->logUpdated(msgString); } } +#else +void Client::logMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + Q_UNUSED(context); + + fprintf(stderr, "%s\n", msg.toLocal8Bit().constData()); + fflush(stderr); + if (type == QtFatalMsg) { + Quassel::logFatalMessage(msg.toLocal8Bit().constData()); + } + else { + QString msgString = QString("%1\n").arg(msg); + + //Check to see if there is an instance around, else we risk recursions + //when calling instance() and creating new ones. + if (!instanceExists()) + return; + + instance()->_debugLog << msgString; + emit instance()->logUpdated(msgString); + } +} +#endif diff --git a/src/client/client.h b/src/client/client.h index e3aacd04..d93c62b4 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -142,7 +142,11 @@ public: static void mergeBuffersPermanently(BufferId bufferId1, BufferId bufferId2); static void purgeKnownBufferIds(); +#if QT_VERSION < 0x050000 static void logMessage(QtMsgType type, const char *msg); +#else + static void logMessage(QtMsgType, const QMessageLogContext&, const QString&); +#endif static inline const QString &debugLog() { return instance()->_debugLogBuffer; } signals: diff --git a/src/common/logger.cpp b/src/common/logger.cpp index d4d676ce..7cb7f4a0 100644 --- a/src/common/logger.cpp +++ b/src/common/logger.cpp @@ -97,6 +97,7 @@ void Logger::log() } +#if QT_VERSION < 0x050000 void Logger::logMessage(QtMsgType type, const char *msg) { switch (type) { @@ -115,3 +116,25 @@ void Logger::logMessage(QtMsgType type, const char *msg) return; } } +#else +void Logger::logMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + Q_UNUSED(context) + + switch (type) { + case QtDebugMsg: + Logger(Quassel::DebugLevel) << msg.toLocal8Bit().constData(); + break; + case QtWarningMsg: + Logger(Quassel::WarningLevel) << msg.toLocal8Bit().constData(); + break; + case QtCriticalMsg: + Logger(Quassel::ErrorLevel) << msg.toLocal8Bit().constData(); + break; + case QtFatalMsg: + Logger(Quassel::ErrorLevel) << msg.toLocal8Bit().constData(); + Quassel::logFatalMessage(msg.toLocal8Bit().constData()); + return; + } +} +#endif diff --git a/src/common/logger.h b/src/common/logger.h index a9861534..2caa5d39 100644 --- a/src/common/logger.h +++ b/src/common/logger.h @@ -33,7 +33,11 @@ public: inline Logger(Quassel::LogLevel level) : _stream(&_buffer, QIODevice::WriteOnly), _logLevel(level) {} ~Logger(); +#if QT_VERSION < 0x050000 static void logMessage(QtMsgType type, const char *msg); +#else + static void logMessage(QtMsgType, const QMessageLogContext&, const QString&); +#endif template inline Logger &operator<<(const T &value) { _stream << value << " "; return *this; } diff --git a/src/core/coreapplication.cpp b/src/core/coreapplication.cpp index 3c123275..2ea44f85 100644 --- a/src/core/coreapplication.cpp +++ b/src/core/coreapplication.cpp @@ -85,7 +85,11 @@ CoreApplication::~CoreApplication() bool CoreApplication::init() { if (Quassel::init() && _internal->init()) { +#if QT_VERSION < 0x050000 qInstallMsgHandler(Logger::logMessage); +#else + qInstallMessageHandler(Logger::logMessage); +#endif return true; } return false; diff --git a/src/qtui/qtuiapplication.cpp b/src/qtui/qtuiapplication.cpp index cf421bc9..cd95678c 100644 --- a/src/qtui/qtuiapplication.cpp +++ b/src/qtui/qtuiapplication.cpp @@ -62,7 +62,11 @@ QtUiApplication::QtUiApplication(int &argc, char **argv) #endif /* HAVE_KDE || Q_OS_MAC */ setRunMode(Quassel::ClientOnly); +#if QT_VERSION < 0x050000 qInstallMsgHandler(Client::logMessage); +#else + qInstallMessageHandler(Client::logMessage); +#endif } -- 2.20.1