feat: Make log writing in other thread.
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user