mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-28 03:49:20 +03:00
Fix crash at exit when there is a log after the Logger has been destroyed
Use a proper static Logger instead of allocating one, and cleanup the QTMessageLogger when it is destroyed
This commit is contained in:
parent
a60902b33d
commit
50ce0f9681
2 changed files with 16 additions and 27 deletions
|
@ -27,6 +27,9 @@ static void mirallLogCatcher(QtMsgType type, const char *msg)
|
||||||
// qDebug() exports to local8Bit, which is not always UTF-8
|
// qDebug() exports to local8Bit, which is not always UTF-8
|
||||||
Logger::instance()->mirallLog( QString::fromLocal8Bit(msg) );
|
Logger::instance()->mirallLog( QString::fromLocal8Bit(msg) );
|
||||||
}
|
}
|
||||||
|
static void qInstallMessageHandler(QtMsgHandler h) {
|
||||||
|
qInstallMsgHandler(h);
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
static void mirallLogCatcher(QtMsgType, const QMessageLogContext &ctx, const QString &message) {
|
static void mirallLogCatcher(QtMsgType, const QMessageLogContext &ctx, const QString &message) {
|
||||||
Q_UNUSED(ctx);
|
Q_UNUSED(ctx);
|
||||||
|
@ -38,35 +41,23 @@ static void mirallLogCatcher(QtMsgType, const QMessageLogContext &ctx, const QSt
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Logger* Logger::_instance=0;
|
|
||||||
|
|
||||||
Logger::Logger( QObject* parent)
|
|
||||||
: QObject(parent),
|
|
||||||
_showTime(true), _doLogging(false), _doFileFlush(false), _logExpire(0)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
Logger *Logger::instance()
|
Logger *Logger::instance()
|
||||||
{
|
{
|
||||||
if( !Logger::_instance ) {
|
static Logger log;
|
||||||
Logger::_instance = new Logger;
|
return &log;
|
||||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
|
||||||
qInstallMsgHandler( mirallLogCatcher );
|
|
||||||
#else
|
|
||||||
qInstallMessageHandler(mirallLogCatcher);
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
return Logger::_instance;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Logger::destroy()
|
Logger::Logger( QObject* parent) : QObject(parent),
|
||||||
|
_showTime(true), _doLogging(false), _doFileFlush(false), _logExpire(0)
|
||||||
{
|
{
|
||||||
if( Logger::_instance ) {
|
qInstallMessageHandler(mirallLogCatcher);
|
||||||
delete Logger::_instance;
|
|
||||||
Logger::_instance = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Logger::~Logger() {
|
||||||
|
qInstallMessageHandler(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Logger::postGuiLog(const QString &title, const QString &message)
|
void Logger::postGuiLog(const QString &title, const QString &message)
|
||||||
{
|
{
|
||||||
emit guiLog(title, message);
|
emit guiLog(title, message);
|
||||||
|
|
|
@ -41,6 +41,7 @@ class OWNCLOUDSYNC_EXPORT Logger : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
|
||||||
void log(Log log);
|
void log(Log log);
|
||||||
|
|
||||||
static void csyncLog( const QString& message );
|
static void csyncLog( const QString& message );
|
||||||
|
@ -49,7 +50,6 @@ public:
|
||||||
const QList<Log>& logs() const {return _logs;}
|
const QList<Log>& logs() const {return _logs;}
|
||||||
|
|
||||||
static Logger* instance();
|
static Logger* instance();
|
||||||
static void destroy();
|
|
||||||
|
|
||||||
void postGuiLog(const QString& title, const QString& message);
|
void postGuiLog(const QString& title, const QString& message);
|
||||||
void postOptionalGuiLog(const QString& title, const QString& message);
|
void postOptionalGuiLog(const QString& title, const QString& message);
|
||||||
|
@ -69,14 +69,12 @@ signals:
|
||||||
public slots:
|
public slots:
|
||||||
void enterNextLogFile();
|
void enterNextLogFile();
|
||||||
|
|
||||||
protected:
|
private:
|
||||||
Logger(QObject* parent=0);
|
Logger(QObject* parent=0);
|
||||||
|
~Logger();
|
||||||
QList<Log> _logs;
|
QList<Log> _logs;
|
||||||
bool _showTime;
|
bool _showTime;
|
||||||
bool _doLogging;
|
bool _doLogging;
|
||||||
|
|
||||||
static Logger* _instance;
|
|
||||||
|
|
||||||
QFile _logFile;
|
QFile _logFile;
|
||||||
bool _doFileFlush;
|
bool _doFileFlush;
|
||||||
int _logExpire;
|
int _logExpire;
|
||||||
|
|
Loading…
Reference in a new issue