From: Jocelyn Turcotte Date: Thu, 8 Dec 2016 16:30:41 +0000 (+0100) Subject: Fix the log window not showing csync logs X-Git-Tag: archive/raspbian/3.16.7-1_deb13u1+rpi1~1^2~969 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=f985111b6286a0c2ef4794495a6976f756a47776;p=nextcloud-desktop.git Fix the log window not showing csync logs 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. --- diff --git a/src/gui/application.cpp b/src/gui/application.cpp index 70c09c434..d67a0537c 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -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) diff --git a/src/gui/logbrowser.cpp b/src/gui/logbrowser.cpp index 18b249174..22e17f80d 100644 --- a/src/gui/logbrowser.cpp +++ b/src/gui/logbrowser.cpp @@ -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")); diff --git a/src/libsync/logger.cpp b/src/libsync/logger.cpp index ab2b5253a..358887a72 100644 --- a/src/libsync/logger.cpp +++ b/src/libsync/logger.cpp @@ -19,6 +19,8 @@ #include #include +#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(&_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(); diff --git a/src/libsync/logger.h b/src/libsync/logger.h index d73d32b69..2f096a7a7 100644 --- a/src/libsync/logger.h +++ b/src/libsync/logger.h @@ -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 _logs; bool _showTime; - bool _doLogging; + bool _logWindowActivated; QFile _logFile; bool _doFileFlush; int _logExpire;