mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 00:14:06 +00:00
fix: log-to-file does not work in multithread
This commit is contained in:
parent
6e52ae601f
commit
821cceef1d
|
@ -29,6 +29,8 @@
|
||||||
#include <QtWebEngineCore/QWebEngineUrlScheme>
|
#include <QtWebEngineCore/QWebEngineUrlScheme>
|
||||||
|
|
||||||
#include "gddebug.hh"
|
#include "gddebug.hh"
|
||||||
|
#include <QMutexLocker>
|
||||||
|
#include <QMutex>
|
||||||
|
|
||||||
#if defined(USE_BREAKPAD)
|
#if defined(USE_BREAKPAD)
|
||||||
#include "client/windows/handler/exception_handler.h"
|
#include "client/windows/handler/exception_handler.h"
|
||||||
|
@ -48,6 +50,8 @@ bool callback(const wchar_t* dump_path, const wchar_t* id,
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
QMutex logMutex;
|
||||||
|
|
||||||
void gdMessageHandler( QtMsgType type, const QMessageLogContext &context, const QString &mess )
|
void gdMessageHandler( QtMsgType type, const QMessageLogContext &context, const QString &mess )
|
||||||
{
|
{
|
||||||
QString strTime = QDateTime::currentDateTime().toString( "MM-dd hh:mm:ss" );
|
QString strTime = QDateTime::currentDateTime().toString( "MM-dd hh:mm:ss" );
|
||||||
|
@ -59,6 +63,8 @@ void gdMessageHandler( QtMsgType type, const QMessageLogContext &context, const
|
||||||
.arg( mess );
|
.arg( mess );
|
||||||
|
|
||||||
if ( ( logFilePtr != nullptr ) && logFilePtr->isOpen() ) {
|
if ( ( logFilePtr != nullptr ) && logFilePtr->isOpen() ) {
|
||||||
|
//without the lock ,on multithread,there would be assert error.
|
||||||
|
QMutexLocker _( &logMutex );
|
||||||
switch ( type ) {
|
switch ( type ) {
|
||||||
case QtDebugMsg:
|
case QtDebugMsg:
|
||||||
message.insert( 0, "Debug: " );
|
message.insert( 0, "Debug: " );
|
||||||
|
@ -84,6 +90,8 @@ void gdMessageHandler( QtMsgType type, const QMessageLogContext &context, const
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//the following code lines actually will have no chance to run, schedule to remove in the future.
|
||||||
QByteArray msg = mess.toUtf8().constData();
|
QByteArray msg = mess.toUtf8().constData();
|
||||||
switch ( type ) {
|
switch ( type ) {
|
||||||
case QtDebugMsg:
|
case QtDebugMsg:
|
||||||
|
|
Loading…
Reference in a new issue