[Pkg-owncloud-commits] [owncloud-client] 04/164: Logger: use qFormatLogMessage with Qt 5.4 so it respects the Qt logging preferences

Sandro Knauß hefee-guest at moszumanska.debian.org
Sun Mar 22 11:55:48 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit d6bdbf9f34794388898e4cc0746708062496aa49
Author: Olivier Goffart <ogoffart at woboq.com>
Date:   Sat Feb 14 14:21:37 2015 +0100

    Logger: use qFormatLogMessage with Qt 5.4 so it respects the Qt logging preferences
---
 src/libsync/logger.cpp | 17 +++++++++++++----
 src/libsync/logger.h   |  1 +
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/src/libsync/logger.cpp b/src/libsync/logger.cpp
index c73ac21..eb3cd91 100644
--- a/src/libsync/logger.cpp
+++ b/src/libsync/logger.cpp
@@ -31,15 +31,17 @@ static void mirallLogCatcher(QtMsgType type, const char *msg)
 static void qInstallMessageHandler(QtMsgHandler h) {
     qInstallMsgHandler(h);
 }
-#else
+#elif QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
 static void mirallLogCatcher(QtMsgType, const QMessageLogContext &ctx, const QString &message) {
-    Q_UNUSED(ctx);
-
     QByteArray file = ctx.file;
     file = file.mid(file.lastIndexOf('/') + 1);
     Logger::instance()->mirallLog( QString::fromLocal8Bit(file) + QLatin1Char(':') + QString::number(ctx.line)
                                     + QLatin1Char(' ')  + message) ;
 }
+#else
+static void mirallLogCatcher(QtMsgType type, const QMessageLogContext &ctx, const QString &message) {
+    Logger::instance()->doLog( qFormatLogMessage(type, ctx, message) ) ;
+}
 #endif
 
 Logger *Logger::instance()
@@ -51,6 +53,9 @@ Logger *Logger::instance()
 Logger::Logger( QObject* parent) : QObject(parent),
   _showTime(true), _doLogging(false), _doFileFlush(false), _logExpire(0)
 {
+#if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
+    qSetMessagePattern("%{time MM-dd hh:mm:ss:zzz} %{threadid} %{function}: %{message}");
+#endif
     qInstallMessageHandler(mirallLogCatcher);
 }
 
@@ -91,6 +96,11 @@ void Logger::log(Log log)
     // _logs.append(log);
     // std::cout << qPrintable(log.message) << std::endl;
 
+    doLog(msg);
+}
+
+void Logger::doLog(const QString& msg)
+{
     {
         QMutexLocker lock(&_mutex);
         if( _logstream ) {
@@ -98,7 +108,6 @@ void Logger::log(Log log)
             if( _doFileFlush ) _logstream->flush();
         }
     }
-
     emit newLog(msg);
 }
 
diff --git a/src/libsync/logger.h b/src/libsync/logger.h
index db9e185..edeefa6 100644
--- a/src/libsync/logger.h
+++ b/src/libsync/logger.h
@@ -43,6 +43,7 @@ class OWNCLOUDSYNC_EXPORT Logger : public QObject
 public:
 
   void log(Log log);
+  void doLog(const QString &log);
 
   static void csyncLog( const QString& message );
   static void mirallLog( const QString& message );

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list