mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-23 21:46:03 +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
|
||||
Logger::instance()->mirallLog( QString::fromLocal8Bit(msg) );
|
||||
}
|
||||
static void qInstallMessageHandler(QtMsgHandler h) {
|
||||
qInstallMsgHandler(h);
|
||||
}
|
||||
#else
|
||||
static void mirallLogCatcher(QtMsgType, const QMessageLogContext &ctx, const QString &message) {
|
||||
Q_UNUSED(ctx);
|
||||
|
@ -38,35 +41,23 @@ static void mirallLogCatcher(QtMsgType, const QMessageLogContext &ctx, const QSt
|
|||
}
|
||||
#endif
|
||||
|
||||
Logger* Logger::_instance=0;
|
||||
|
||||
Logger::Logger( QObject* parent)
|
||||
: QObject(parent),
|
||||
_showTime(true), _doLogging(false), _doFileFlush(false), _logExpire(0)
|
||||
{
|
||||
}
|
||||
|
||||
Logger *Logger::instance()
|
||||
{
|
||||
if( !Logger::_instance ) {
|
||||
Logger::_instance = new Logger;
|
||||
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
|
||||
qInstallMsgHandler( mirallLogCatcher );
|
||||
#else
|
||||
qInstallMessageHandler(mirallLogCatcher);
|
||||
#endif
|
||||
}
|
||||
return Logger::_instance;
|
||||
static Logger log;
|
||||
return &log;
|
||||
}
|
||||
|
||||
void Logger::destroy()
|
||||
Logger::Logger( QObject* parent) : QObject(parent),
|
||||
_showTime(true), _doLogging(false), _doFileFlush(false), _logExpire(0)
|
||||
{
|
||||
if( Logger::_instance ) {
|
||||
delete Logger::_instance;
|
||||
Logger::_instance = 0;
|
||||
}
|
||||
qInstallMessageHandler(mirallLogCatcher);
|
||||
}
|
||||
|
||||
Logger::~Logger() {
|
||||
qInstallMessageHandler(0);
|
||||
}
|
||||
|
||||
|
||||
void Logger::postGuiLog(const QString &title, const QString &message)
|
||||
{
|
||||
emit guiLog(title, message);
|
||||
|
|
|
@ -41,6 +41,7 @@ class OWNCLOUDSYNC_EXPORT Logger : public QObject
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
void log(Log log);
|
||||
|
||||
static void csyncLog( const QString& message );
|
||||
|
@ -49,7 +50,6 @@ public:
|
|||
const QList<Log>& logs() const {return _logs;}
|
||||
|
||||
static Logger* instance();
|
||||
static void destroy();
|
||||
|
||||
void postGuiLog(const QString& title, const QString& message);
|
||||
void postOptionalGuiLog(const QString& title, const QString& message);
|
||||
|
@ -69,14 +69,12 @@ signals:
|
|||
public slots:
|
||||
void enterNextLogFile();
|
||||
|
||||
protected:
|
||||
private:
|
||||
Logger(QObject* parent=0);
|
||||
~Logger();
|
||||
QList<Log> _logs;
|
||||
bool _showTime;
|
||||
bool _doLogging;
|
||||
|
||||
static Logger* _instance;
|
||||
|
||||
QFile _logFile;
|
||||
bool _doFileFlush;
|
||||
int _logExpire;
|
||||
|
|
Loading…
Reference in a new issue