mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
threadify file logger
This commit is contained in:
parent
f29305bb01
commit
922bcb2384
@ -24,10 +24,12 @@
|
||||
#include <QFile>
|
||||
#include <QDir>
|
||||
#include <QDateTime>
|
||||
#include <QMutexLocker>
|
||||
|
||||
#ifdef LOG_TO_FILE
|
||||
static QtMessageHandler dflt;
|
||||
static QTextStream* logFile {nullptr};
|
||||
static QMutex mutex;
|
||||
|
||||
void myMessageHandler(QtMsgType type, const QMessageLogContext& ctxt, const QString& msg)
|
||||
{
|
||||
@ -39,7 +41,8 @@ void myMessageHandler(QtMsgType type, const QMessageLogContext& ctxt, const QStr
|
||||
&& msg == QString("QFSFileEngine::open: No file name specified"))
|
||||
return;
|
||||
|
||||
dflt(type, ctxt, msg);
|
||||
dflt(type, ctxt, msg); // this must be thread safe, otherwise qDebug() would never ever work
|
||||
QMutexLocker locker(&mutex);
|
||||
*logFile << QTime::currentTime().toString("HH:mm:ss' '") << msg << '\n';
|
||||
logFile->flush();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user