feat: Add system log.
This commit is contained in:
@@ -15,11 +15,11 @@
|
||||
#include "event/EventCenter.h"
|
||||
QString fileNameToDate(QString fileName)
|
||||
{
|
||||
return fileName.split("log/")[1].replace("-op.log", "");
|
||||
return fileName.split("log/UserOperationLog/")[1].replace("-op.log", "");
|
||||
}
|
||||
QString dateToFileName(QString date)
|
||||
{
|
||||
return QString("./log/") + date + QString("-op.log");
|
||||
return QString("./log/UserOperationLog/") + date + QString("-op.log");
|
||||
}
|
||||
|
||||
UserOperationLogForm::UserOperationLogForm(QWidget* parent) {
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "dialogs/MultyMessageDialog.h"
|
||||
#include "UsctStateManager.h"
|
||||
#include "utilities/ScanProcessSequence.h"
|
||||
#include "log/SystemOperationLog.h"
|
||||
|
||||
#define TRIGGER_EVENT EventCenter::Default()->triggerEvent
|
||||
|
||||
@@ -753,6 +754,7 @@ void DeviceManager::processAlarm(const QString& aAlarm)
|
||||
int alarmCode = jsonObj["code"].toInt();
|
||||
QString alarm = QString::number(alarmCode);
|
||||
qDebug()<<"processAlarm : "<<alarmCode;
|
||||
LOG_SYS_OPERATION("Dms alarm reported. code: " + alarm)
|
||||
if(alarmCode >= 400 && alarmCode < 500)
|
||||
{
|
||||
if(mIsScanning)
|
||||
@@ -823,6 +825,7 @@ bool DeviceManager::startFullScan(const QString& aPatientInfo)
|
||||
{
|
||||
QString message = QString("Dms connection error. Reason:%1").arg(result.mData);
|
||||
THROW_ERROR(message);
|
||||
LOG_SYS_OPERATION("Start full scan failed. " + message)
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -831,10 +834,12 @@ bool DeviceManager::startFullScan(const QString& aPatientInfo)
|
||||
if(code != 0)
|
||||
{
|
||||
QString msg = jsonObj["info"].toString();
|
||||
LOG_SYS_OPERATION("Start full scan failed. " + msg)
|
||||
THROW_ERROR(msg);
|
||||
return false;
|
||||
}
|
||||
mCurrentScanMeasurementID = jsonObj["measurement id"].toString();
|
||||
//LOG_SYS_OPERATION("Start full scan succeed.")
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1263,12 +1268,14 @@ void DeviceManager::updateReconConnectionState(bool aIsConnected)
|
||||
|
||||
void DeviceManager::startScanProcess()
|
||||
{
|
||||
LOG_SYS_OPERATION("Start scan process.")
|
||||
if( !UsctStateManager::getInstance()->getState(ReconConnectionState) ||
|
||||
!UsctStateManager::getInstance()->getState(ReconState) ||
|
||||
!UsctStateManager::getInstance()->getState(ReconDBState))
|
||||
{
|
||||
TRIGGER_EVENT(StopScanProcess, nullptr, nullptr);
|
||||
QString errorMessage = tr("Recon error, can't start scan process");
|
||||
LOG_SYS_OPERATION(errorMessage)
|
||||
TRIGGER_EVENT(StopScanProcess, nullptr, nullptr);
|
||||
THROW_ERROR(errorMessage);
|
||||
return;
|
||||
}
|
||||
@@ -1279,6 +1286,7 @@ void DeviceManager::startScanProcess()
|
||||
void DeviceManager::stopScanProcess()
|
||||
{
|
||||
AppGlobalValues::setInProcessing(false);
|
||||
LOG_SYS_OPERATION("Stop scan process.")
|
||||
stopAutoLocate();
|
||||
}
|
||||
|
||||
@@ -1298,12 +1306,14 @@ bool DeviceManager::startAutoLocate()
|
||||
{
|
||||
emit startAutoLocateResult(true);
|
||||
mGetAutoLocatePositionTimer = startTimer(1000);
|
||||
//LOG_SYS_OPERATION("Start auto locate succeed.")
|
||||
return true;
|
||||
}
|
||||
}
|
||||
TRIGGER_EVENT(StopScanProcess, nullptr, nullptr);
|
||||
QString errorMessage = tr("Start auto locate failed");
|
||||
THROW_ERROR(errorMessage)
|
||||
LOG_SYS_OPERATION("Start auto locate failed.")
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1366,11 +1376,13 @@ void DeviceManager::checkDataQuality()
|
||||
QJsonObject jsonObj = toJsonObject(result.mData);
|
||||
if(jsonObj["qualities"].toInt() == 1 )
|
||||
{
|
||||
LOG_SYS_OPERATION("Check data quality succeed. Data quality is good.")
|
||||
prepareFinishScan(true);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_SYS_OPERATION("Check data quality succeed. Data quality is bad.")
|
||||
QString errorMessage = tr("The data quality is low, please restart the data scan.") + jsonObj["info"].toString();
|
||||
prepareFinishScan(false, errorMessage);
|
||||
TRIGGER_EVENT(StopScanProcess, nullptr, nullptr);
|
||||
@@ -1380,6 +1392,7 @@ void DeviceManager::checkDataQuality()
|
||||
QString errorMessage = tr("Dms connection error");
|
||||
prepareFinishScan(false, errorMessage);
|
||||
TRIGGER_EVENT(StopScanProcess, nullptr, nullptr);
|
||||
LOG_SYS_OPERATION("Check data quality failed. " + errorMessage)
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "UsctStateManager.h"
|
||||
|
||||
#include "event/EventCenter.h"
|
||||
#include "log/SystemOperationLog.h"
|
||||
|
||||
UsctStateManager* UsctStateManager::getInstance()
|
||||
{
|
||||
@@ -34,11 +35,14 @@ void UsctStateManager::setState(int aStateCode, bool aState)
|
||||
if(aState)
|
||||
{
|
||||
int msg = aStateCode;
|
||||
LOG_SYS_OPERATION(getStateErrorMessage(aStateCode) + " recovery.")
|
||||
EventCenter::Default()->triggerEvent(ErrorStateUnactive, nullptr, (QObject*)&msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
QPair<int, QString> msg(QPair<int, QString>(aStateCode, getStateErrorMessage(aStateCode)));
|
||||
QString errorMessage = getStateErrorMessage(aStateCode);
|
||||
LOG_SYS_OPERATION(errorMessage)
|
||||
QPair<int, QString> msg(QPair<int, QString>(aStateCode, errorMessage));
|
||||
EventCenter::Default()->triggerEvent(ErrorStateActive, nullptr, (QObject*)&msg);
|
||||
}
|
||||
}
|
||||
|
||||
72
src/log/SystemOperationLog.cpp
Normal file
72
src/log/SystemOperationLog.cpp
Normal file
@@ -0,0 +1,72 @@
|
||||
#include "SystemOperationLog.h"
|
||||
|
||||
#include "appvals/AppGlobalValues.h"
|
||||
|
||||
#include <QDir>
|
||||
|
||||
namespace
|
||||
{
|
||||
const QString LOG_DIR = "./log/SystemOperationLog";
|
||||
const QString SYS_LOG_SUFFIX = "-sys.log";
|
||||
}
|
||||
|
||||
SystemOperationLog* SystemOperationLog::getInstance()
|
||||
{
|
||||
static SystemOperationLog instance;
|
||||
return &instance;
|
||||
}
|
||||
|
||||
|
||||
SystemOperationLog::SystemOperationLog()
|
||||
: mCurrentFileName()
|
||||
, mLogFile()
|
||||
, mStreamOut()
|
||||
{
|
||||
QDir log_dir("./");
|
||||
if (!log_dir.exists("log")) log_dir.mkdir("log");
|
||||
if (!log_dir.exists(LOG_DIR)) log_dir.mkdir(LOG_DIR);
|
||||
mCurrentFileName = LOG_DIR + QDate::currentDate().toString("/yyyy-MM-dd") + SYS_LOG_SUFFIX;
|
||||
mLogFile.setFileName(mCurrentFileName);
|
||||
if (mLogFile.exists())
|
||||
{
|
||||
mLogFile.open(QFile::OpenModeFlag::Append | QFile::OpenModeFlag::Text);
|
||||
}
|
||||
else
|
||||
{
|
||||
mLogFile.open(QFile::OpenModeFlag::NewOnly | QFile::OpenModeFlag::Text);
|
||||
}
|
||||
mStreamOut.setDevice(&mLogFile);
|
||||
}
|
||||
|
||||
SystemOperationLog::~SystemOperationLog()
|
||||
{
|
||||
if (mLogFile.isOpen())
|
||||
{
|
||||
mLogFile.flush();
|
||||
mLogFile.close();
|
||||
}
|
||||
}
|
||||
|
||||
void SystemOperationLog::reloadFile()
|
||||
{
|
||||
QString newFileName = LOG_DIR + QDate::currentDate().toString("/yyyy-MM-dd") + SYS_LOG_SUFFIX;
|
||||
if (newFileName == mCurrentFileName && !AppGlobalValues::InProcessing().toBool()) return;
|
||||
mLogFile.close();
|
||||
mLogFile.setFileName(newFileName);
|
||||
if (mLogFile.exists())
|
||||
{
|
||||
mLogFile.open(QFile::OpenModeFlag::Append | QFile::OpenModeFlag::Text);
|
||||
}
|
||||
else
|
||||
{
|
||||
mLogFile.open(QFile::OpenModeFlag::NewOnly | QFile::OpenModeFlag::Text);
|
||||
}
|
||||
mStreamOut.setDevice(&mLogFile);
|
||||
}
|
||||
|
||||
void SystemOperationLog::log(const QString &aOperationText)
|
||||
{
|
||||
reloadFile();
|
||||
QDateTime now = QDateTime::currentDateTime();
|
||||
mStreamOut << now.toString(Qt::DateFormat::ISODateWithMs).replace("T","\t")<<"\t"<<aOperationText<<endl;
|
||||
}
|
||||
28
src/log/SystemOperationLog.h
Normal file
28
src/log/SystemOperationLog.h
Normal file
@@ -0,0 +1,28 @@
|
||||
#ifndef SYSTEMOPERATIONLOG_H
|
||||
#define SYSTEMOPERATIONLOG_H
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QFile>
|
||||
#include <QTextStream>
|
||||
|
||||
#define LOG_SYS_OPERATION(...)\
|
||||
SystemOperationLog::getInstance()->log(__VA_ARGS__);
|
||||
|
||||
class SystemOperationLog
|
||||
{
|
||||
public:
|
||||
static SystemOperationLog* getInstance();
|
||||
void log(const QString& aOperationText);
|
||||
void reloadFile();
|
||||
|
||||
private:
|
||||
SystemOperationLog();
|
||||
~SystemOperationLog();
|
||||
|
||||
private:
|
||||
QString mCurrentFileName;
|
||||
QFile mLogFile;
|
||||
QTextStream mStreamOut;
|
||||
};
|
||||
|
||||
#endif // SYSTEMOPERATIONLOG_H
|
||||
@@ -9,12 +9,13 @@
|
||||
|
||||
namespace
|
||||
{
|
||||
const QString logDir = "./log";
|
||||
const QString logDir = "./log/UserOperationLog";
|
||||
}
|
||||
|
||||
void UserOperationLog::init() {
|
||||
QDir log_dir("./");
|
||||
if (!log_dir.exists(logDir)) log_dir.mkdir("log");
|
||||
if (!log_dir.exists("log")) log_dir.mkdir("log");
|
||||
if (!log_dir.exists(logDir)) log_dir.mkdir(logDir);
|
||||
currentFileName = logDir + QDate::currentDate().toString("/yyyy-MM-dd")+QString("-op.log");
|
||||
logFile.setFileName(currentFileName);
|
||||
if (logFile.exists())
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "utilities/TouchScreenSignalSender.h"
|
||||
#include "keyboard/KeyboardManager.h"
|
||||
#include "appvals/AppGlobalValues.h"
|
||||
#include "log/SystemOperationLog.h"
|
||||
#include <QFileSystemWatcher>
|
||||
|
||||
QString loadFontFromFile(QString path)
|
||||
@@ -93,6 +94,7 @@ int main(int argc, char* argv[])
|
||||
MainWindow w;
|
||||
DialogManager::Default()->init(&w);
|
||||
UserOperationLog::Default()->init();
|
||||
SystemOperationLog::getInstance();
|
||||
|
||||
QObject::connect(TouchScreenSignalSender::getInstance(), SIGNAL(touchScreen()), Locker::getInstance(), SLOT(refreshTimer()));
|
||||
QList<Qt::GestureType> gestures;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include "ReconManager.h"
|
||||
#include "ReconClient.h"
|
||||
#include "json/jsonobject.h"
|
||||
#include "log/SystemOperationLog.h"
|
||||
|
||||
#include <QTimer>
|
||||
#include "QDebug"
|
||||
@@ -54,11 +55,13 @@ void ReconManager::createEmptyScan(const QString& aScanID, const QString& aPath)
|
||||
if(result.good())
|
||||
{
|
||||
qDebug()<< "create empty scan success, scanID: "<< aScanID;
|
||||
LOG_SYS_OPERATION("create empty scan success, scanID: " + aScanID)
|
||||
emit createEmptyScanResponsed(true, aScanID);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug()<< "Create empty scan fail by %s\n" << result.error().data();
|
||||
LOG_SYS_OPERATION("Create empty scan failed. " + QString(result.error().data()))
|
||||
emit createEmptyScanResponsed(false, aScanID, result.error().data());
|
||||
}
|
||||
}
|
||||
@@ -70,11 +73,13 @@ void ReconManager::createScan(const QString& aScanID, const QString& aStudyUID,c
|
||||
if(response.good())
|
||||
{
|
||||
qDebug()<< "Recon create scan success, scanID: "<< aScanID;
|
||||
LOG_SYS_OPERATION("Recon create scan success, scanID: " + aScanID)
|
||||
emit createScanResponsed(true, aScanID);
|
||||
}
|
||||
else
|
||||
{
|
||||
qDebug()<< "Recon create scan failed by " << response.error().data();
|
||||
LOG_SYS_OPERATION("Recon create scan failed" + QString(response.error().data()))
|
||||
emit createScanResponsed(false, aScanID, response.error().data());
|
||||
}
|
||||
}
|
||||
@@ -130,11 +135,13 @@ void ReconManager::setPacsSettings(const QString& aClientAETitle, const QString&
|
||||
{
|
||||
QString msg = QString("Set PACS settings failed : ") + response.error().data();
|
||||
qDebug()<< msg;
|
||||
LOG_SYS_OPERATION(msg)
|
||||
emit setPacsSettingsResponsed(false, QVariant::fromValue(msg));
|
||||
return;
|
||||
}
|
||||
|
||||
emit setPacsSettingsResponsed(true, QVariant::fromValue(QString("Set PACS settings succeed.")));
|
||||
QString message = "Set PACS settings succeed.";
|
||||
LOG_SYS_OPERATION(message)
|
||||
emit setPacsSettingsResponsed(true, QVariant::fromValue(message));
|
||||
}
|
||||
|
||||
void ReconManager::setMppsSettings(bool aIsOpen, const QString& aServerAETitle, const QString& aServerIP, int aServerPort)
|
||||
@@ -145,11 +152,13 @@ void ReconManager::setMppsSettings(bool aIsOpen, const QString& aServerAETitle,
|
||||
{
|
||||
QString msg = QString("Set MPPS settings failed : ") + response.error().data();
|
||||
qDebug()<< msg;
|
||||
LOG_SYS_OPERATION(msg)
|
||||
emit setMppsSettingsResponsed(false, QVariant::fromValue(msg));
|
||||
return;
|
||||
}
|
||||
|
||||
emit setMppsSettingsResponsed(true, QVariant::fromValue(QString("Set MPPS settings succeed.")));
|
||||
QString message = "Set MPPS settings succeed.";
|
||||
LOG_SYS_OPERATION(message)
|
||||
emit setMppsSettingsResponsed(true, QVariant::fromValue(message));
|
||||
}
|
||||
|
||||
void ReconManager::getReconVersion()
|
||||
|
||||
Reference in New Issue
Block a user