Fix the log window not showing csync logs
authorJocelyn Turcotte <jturcotte@woboq.com>
Thu, 8 Dec 2016 16:30:41 +0000 (17:30 +0100)
committerJocelyn Turcotte <jturcotte@woboq.com>
Fri, 9 Dec 2016 09:03:46 +0000 (10:03 +0100)
The csync log level was only set up on startup, and for log files.
Fix the issue by making Logger::isNoop rely on being explicitly activated
for the log window instead of relying on the presence of a connected
signal, and move the csync log level logic in Logger.

src/gui/application.cpp
src/gui/logbrowser.cpp
src/libsync/logger.cpp
src/libsync/logger.h

index 70c09c4347a98f28b00ccd36d831cafb5ceaedfa..d67a0537cd2ffe95fe54da4156386fd5d11cb586 100644 (file)
@@ -347,14 +347,6 @@ void Application::slotownCloudWizardDone( int res )
     }
 }
 
-static void csyncLogCatcher(int /*verbosity*/,
-                        const char */*function*/,
-                        const char *buffer,
-                        void */*userdata*/)
-{
-    Logger::instance()->csyncLog( QString::fromUtf8(buffer) );
-}
-
 void Application::setupLogging()
 {
     // might be called from second instance
@@ -370,10 +362,6 @@ void Application::setupLogging()
                 .arg(property("ui_lang").toString())
                 .arg(_theme->version())
                 .arg(Utility::platformName());
-
-    // Setup CSYNC logging to forward to our own logger
-    csync_set_log_callback( csyncLogCatcher );
-    csync_set_log_level( Logger::instance()->isNoop() ? 0 : 11 );
 }
 
 void Application::slotUseMonoIconsChanged(bool)
index 18b249174149f340f8935aa4458428d687dec200..22e17f80d29cab156aaf964a437aaa979f658d0b 100644 (file)
@@ -110,8 +110,9 @@ LogBrowser::LogBrowser(QWidget *parent) :
 
     setModal(false);
 
+    Logger::instance()->setLogWindowActivated(true);
     // Direct connection for log coming from this thread, and queued for the one in a different thread
-    connect(Logger::instance(), SIGNAL(newLog(QString)),this,SLOT(slotNewLog(QString)), Qt::AutoConnection);
+    connect(Logger::instance(), SIGNAL(logWindowLog(QString)),this,SLOT(slotNewLog(QString)), Qt::AutoConnection);
 
     QAction *showLogWindow = new QAction(this);
     showLogWindow->setShortcut(QKeySequence("F12"));
index ab2b5253ad75fbd0857cccb592e1ce1af60ea531..358887a7250b9f8c496873b2b096ed2a0bfbb7a8 100644 (file)
@@ -19,6 +19,8 @@
 #include <QThread>
 #include <qmetaobject.h>
 
+#include "csync.h"
+
 namespace OCC {
 
 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
@@ -48,6 +50,14 @@ static void mirallLogCatcher(QtMsgType type, const QMessageLogContext &ctx, cons
 }
 #endif
 
+static void csyncLogCatcher(int /*verbosity*/,
+                        const char * /*function*/,
+                        const char *buffer,
+                        void * /*userdata*/)
+{
+    Logger::instance()->csyncLog( QString::fromUtf8(buffer) );
+}
+
 Logger *Logger::instance()
 {
     static Logger log;
@@ -55,7 +65,7 @@ Logger *Logger::instance()
 }
 
 Logger::Logger( QObject* parent) : QObject(parent),
-  _showTime(true), _doLogging(false), _doFileFlush(false), _logExpire(0)
+  _showTime(true), _logWindowActivated(false), _doFileFlush(false), _logExpire(0)
 {
 #ifndef NO_MSG_HANDLER
 #if QT_VERSION >= QT_VERSION_CHECK(5, 4, 0)
@@ -117,12 +127,8 @@ bool Logger::isNoop() const
 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
     return false;
 #else
-    static auto signal = QMetaMethod::fromSignal(&Logger::newLog);
-    if (isSignalConnected(signal)) {
-        return false;
-    }
     QMutexLocker lock(const_cast<QMutex *>(&_mutex));
-    return !_logstream;
+    return !_logstream && !_logWindowActivated;
 #endif
 }
 
@@ -136,7 +142,7 @@ void Logger::doLog(const QString& msg)
             if( _doFileFlush ) _logstream->flush();
         }
     }
-    emit newLog(msg);
+    emit logWindowLog(msg);
 }
 
 void Logger::csyncLog( const QString& message )
@@ -164,10 +170,25 @@ void Logger::mirallLog( const QString& message )
     Logger::instance()->log( log_ );
 }
 
+void Logger::setLogWindowActivated(bool activated)
+{
+    QMutexLocker locker(&_mutex);
+
+    // Setup CSYNC logging to forward to our own logger
+    csync_set_log_callback(csyncLogCatcher);
+    csync_set_log_level(11);
+
+    _logWindowActivated = activated;
+}
+
 void Logger::setLogFile(const QString & name)
 {
     QMutexLocker locker(&_mutex);
 
+    // Setup CSYNC logging to forward to our own logger
+    csync_set_log_callback(csyncLogCatcher);
+    csync_set_log_level(11);
+
     if( _logstream ) {
         _logstream.reset(0);
         _logFile.close();
index d73d32b693fc24eee787d01ece2a2204e90d961d..2f096a7a7cea405225d8e504e29cd92cb167de99 100644 (file)
@@ -61,13 +61,15 @@ public:
   void postOptionalGuiLog(const QString& title, const QString& message);
   void postGuiMessage(const QString& title, const QString& message);
 
+  void setLogWindowActivated(bool activated);
   void setLogFile( const QString & name );
   void setLogExpire( int expire );
   void setLogDir( const QString& dir );
   void setLogFlush( bool flush );
 
 signals:
-  void newLog(const QString&);
+  void logWindowLog(const QString&);
+
   void guiLog(const QString&, const QString&);
   void guiMessage(const QString&, const QString&);
   void optionalGuiLog(const QString&, const QString&);
@@ -80,7 +82,7 @@ private:
   ~Logger();
   QList<Log> _logs;
   bool       _showTime;
-  bool       _doLogging;
+  bool       _logWindowActivated;
   QFile       _logFile;
   bool        _doFileFlush;
   int         _logExpire;