Logging changed in Qt 5; use QtMessageHandler
authorBas Pape <baspape@gmail.com>
Sat, 20 Apr 2013 22:04:41 +0000 (00:04 +0200)
committerManuel Nickschas <sputnick@quassel-irc.org>
Mon, 24 Mar 2014 23:21:26 +0000 (00:21 +0100)
src/client/client.cpp
src/client/client.h
src/common/logger.cpp
src/common/logger.h
src/core/coreapplication.cpp
src/qtui/qtuiapplication.cpp

index 9ef23ef..3305f5b 100644 (file)
@@ -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
index e3aacd0..d93c62b 100644 (file)
@@ -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:
index d4d676c..7cb7f4a 100644 (file)
@@ -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
index a986153..2caa5d3 100644 (file)
@@ -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<typename T>
     inline Logger &operator<<(const T &value) { _stream << value << " "; return *this; }
index 3c12327..2ea44f8 100644 (file)
@@ -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;
index cf421bc..cd95678 100644 (file)
@@ -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
 }