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.
This commit is contained in:
Jocelyn Turcotte 2016-12-08 17:30:41 +01:00
parent e8d734b1c2
commit f985111b62
4 changed files with 34 additions and 22 deletions

View 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)

View 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"));

View 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();

View 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;