feat: Make log writing in other thread.

This commit is contained in:
sunwen
2024-09-09 09:51:38 +08:00
parent b60c4a8be9
commit 998e0b187a
9 changed files with 14 additions and 13 deletions

View File

@@ -25,7 +25,7 @@
"lockscreen": "0",
"CompleteNotify": true,
"ScanConfirm": false,
"AnonymousMode": false
"AnonymousMode": false,
},
"protocol": {
"default": "0",
@@ -101,8 +101,8 @@
}]
},
"worklistfilter": {
"default": "Recent3Days",
"lists": "Today;Recent3Days;ThisWeek;ThisMonth"
"modality": "US",
"date": "0"
},
"screensaver": {
"open": false,

View File

@@ -1,5 +1,6 @@
#include "DmsAsyncAction.h"
#include "dms_mq.h"
#include "log/LogManager.h"
#include <QTimer>
@@ -17,7 +18,6 @@ DmsAsyncAction::DmsAsyncAction(int aServerId, int aActionId, QObject* aObject, c
, mResponseSignal(aResponseSignal)
, mSendData()
, mIsResponsed(false)
, mIsRunning(false)
{
mTimer->setSingleShot(true);
mTimer->setInterval(TIMEOUT_MSEC);
@@ -45,6 +45,7 @@ bool DmsAsyncAction::execute()
{
return false;
}
LOG_SYS_OPERATION(QString("GUI -> DMS : %1-%2, Message:%3").arg(mServerId).arg(mActionId).arg(mSendData));
mTimer->start();
return true;
}

View File

@@ -43,7 +43,6 @@ private:
QString mResponseSignal;
QString mSendData;
bool mIsResponsed;
bool mIsRunning;
};
#endif // DMSASYNCACTION_H

View File

@@ -25,6 +25,7 @@ DmsSyncAction::DmsSyncAction(int aServerId, int aActionId, QObject* aObject, con
{
mTimer->setSingleShot(true);
connect(mObject, ("2" + mSignal).toStdString().c_str(), this, SLOT(saveActionResult(const QString&)));
connect(mObject, ("2" + mSignal).toStdString().c_str(), mTimer, SLOT(stop()));
connect(mObject, ("2" + mSignal).toStdString().c_str(), mLoop, SLOT(quit()));
connect(mTimer, &QTimer::timeout, mLoop, &QEventLoop::quit);
}
@@ -49,6 +50,7 @@ DmsSyncActionResult DmsSyncAction::execute()
LOG_SYS_OPERATION(QString("GUI -> DMS : %1-%2, Message:%3").arg(mServerId).arg(mActionId).arg(mSendData));
if(!waitUntilSignalReceived())
{
LOG_SYS_OPERATION(QString("GUI -> DMS : %1-%2, Time out.").arg(mServerId).arg(mActionId));
DmsSyncActionResult result(false, "time out");
return result;
}

View File

@@ -33,7 +33,7 @@ LogManager::~LogManager()
void LogManager::writeSystemOperationLog(const QString& aMessage)
{
emit doWriteSystemOperationLog(aMessage);
emit doWriteSystemOperationLog(aMessage, QDateTime::currentDateTime());
}
void LogManager::writeUserOperationLog(const QString& aMessage)

View File

@@ -25,7 +25,7 @@ public:
QString getCurrentUserOperationLogFile();
signals:
void doWriteSystemOperationLog(const QString& aMessage);
void doWriteSystemOperationLog(const QString& aMessage, const QDateTime& aOperationDate);
void doWriteUserOperationLog(const QString& aMessage);
private:

View File

@@ -44,7 +44,7 @@ SystemOperationLog::~SystemOperationLog()
void SystemOperationLog::reloadFile()
{
QString newFileName = LOG_DIR + QDate::currentDate().toString("/yyyy-MM-dd") + SYS_LOG_SUFFIX;
if (newFileName == mCurrentFileName && !AppGlobalValues::InProcessing().toBool()) return;
if (newFileName == mCurrentFileName) return;
mLogFile.close();
mLogFile.setFileName(newFileName);
if (mLogFile.exists())
@@ -58,9 +58,8 @@ void SystemOperationLog::reloadFile()
mStreamOut.setDevice(&mLogFile);
}
void SystemOperationLog::log(const QString &aOperationText)
void SystemOperationLog::log(const QString &aOperationText, const QDateTime& aOperationDate)
{
reloadFile();
QDateTime now = QDateTime::currentDateTime();
mStreamOut << now.toString(Qt::DateFormat::ISODateWithMs).replace("T","\t")<<"\t"<<aOperationText<<endl;
mStreamOut << aOperationDate.toString(Qt::DateFormat::ISODateWithMs).replace("T","\t")<<"\t"<<aOperationText<<endl;
}

View File

@@ -15,7 +15,7 @@ public:
void reloadFile();
public slots:
void log(const QString& aOperationText);
void log(const QString& aOperationText, const QDateTime& aOperationDate);
private:
QString mCurrentFileName;

View File

@@ -74,7 +74,7 @@ void UserOperationLog::log(const QString& aOperationText)
void UserOperationLog::reloadFile() {
QString newFileName = logDir + QDate::currentDate().toString("/yyyy-MM-dd")+QString("-op.log");
//inprocessing 暂时没有使用
if (newFileName == currentFileName && !AppGlobalValues::InProcessing().toBool()) return;
if (newFileName == currentFileName) return;
logFile.close();
logFile.setFileName(newFileName);
if (logFile.exists())