diff --git a/CellFrameDashboardGUI/DapCommandController.cpp b/CellFrameDashboardGUI/DapCommandController.cpp index 7a3cc5b53de45d920665fec3267f6817a65b5228..99f4dd5de8e8b4ddb2e6e870e153999d46f863ad 100755 --- a/CellFrameDashboardGUI/DapCommandController.cpp +++ b/CellFrameDashboardGUI/DapCommandController.cpp @@ -39,11 +39,6 @@ void DapCommandController::processCommandResult() emit sigCommandResult(reply->response().result()); } -void DapCommandController::clearLogModel() -{ - emit onClearLogModel(); -} - /// Get node logs. void DapCommandController::getNodeLogs() { @@ -68,7 +63,7 @@ void DapCommandController::processChangedLog() // QStringList tempLogModel; // for(int x{0}; x < aLogModel.count(); ++x) // tempLogModel.append(aLogModel.at(x).toString()); - emit onLogModel(); + emit onChangeLogModel(); } /// Handling service response for receiving node logs. diff --git a/CellFrameDashboardGUI/DapCommandController.h b/CellFrameDashboardGUI/DapCommandController.h index 78152aba32eeedf940eb598e22dec277ae26d01c..fcfce521328ee344062e6c677b296aca9b0a9748 100755 --- a/CellFrameDashboardGUI/DapCommandController.h +++ b/CellFrameDashboardGUI/DapCommandController.h @@ -42,10 +42,8 @@ signals: void sendNodeStatus(const QVariant& aData); /// void executeCommandChanged(const QString& result); - /// Signal for cleaning log - void onClearLogModel(); - /// - void onLogModel(); + /// Signal for changing logs + void onChangeLogModel(); /// Signal for sending new transaction history void sendHistory(const QVariant& aData); @@ -102,7 +100,6 @@ public slots: void executeCommand(const QString& command); - void clearLogModel(); /// Get node logs. void getNodeLogs(); diff --git a/CellFrameDashboardGUI/DapServiceController.cpp b/CellFrameDashboardGUI/DapServiceController.cpp index 3b8f210afcb6fa1dfc3e9db0a74c6d9c234cd110..514393449a2102a1bfab55d49030fcdc4b3f4b54 100755 --- a/CellFrameDashboardGUI/DapServiceController.cpp +++ b/CellFrameDashboardGUI/DapServiceController.cpp @@ -3,6 +3,8 @@ #include "DapLogMessage.h" #include "DapChainWallet.h" +#include <QRegularExpression> + DapServiceController::DapServiceController(QObject *apParent) : QObject(apParent) { @@ -29,6 +31,8 @@ void DapServiceController::closeClient() void DapServiceController::init(DapServiceClient *apDapServiceClient) { m_pDapServiceClient = apDapServiceClient; + + connect(m_pDapServiceClient, SIGNAL(sigDisconnected()), SLOT(clearLogModel())); // Creating rpc controller m_pDapCommandController = new DapCommandController(apDapServiceClient->getClientSocket(), this); @@ -51,7 +55,7 @@ void DapServiceController::init(DapServiceClient *apDapServiceClient) connect(m_pDapCommandController, SIGNAL(executeCommandChanged(QString)), SLOT(processExecuteCommandInfo(QString))); connect(m_pDapCommandController, SIGNAL(sendNodeNetwork(QVariant)), this, SLOT(processGetNodeNetwork(QVariant))); - connect(m_pDapCommandController, SIGNAL(onLogModel()), SLOT(get())); + connect(m_pDapCommandController, SIGNAL(onChangeLogModel()), SLOT(getNodeLogs())); connect(&DapChainNodeNetworkModel::getInstance(), SIGNAL(requestNodeNetwork()), this, SLOT(getNodeNetwork())); connect(&DapChainNodeNetworkModel::getInstance(), SIGNAL(requestNodeStatus(bool)), this, SLOT(setNodeStatus(bool))); @@ -80,7 +84,7 @@ QString DapServiceController::getResult() void DapServiceController::getWallets() const { - qInfo() << QString("getNodeLogs()"); + qInfo() << QString("getWallets()"); m_pDapCommandController->getWallets(); } @@ -88,44 +92,26 @@ void DapServiceController::getWallets() const /// @param aNodeLogs List of node logs. void DapServiceController::processGetNodeLogs(const QStringList &aNodeLogs) { - if(aNodeLogs.count() <= 0) + if(aNodeLogs.isEmpty()) return; - int counter {0}; - QStringList list; + int xx = DapLogModel::getInstance().rowCount(); - for(int x{0}; x <= aNodeLogs.size(); ++x) + QRegularExpression re("(?<=])\\s"); + for (auto const & log : aNodeLogs) { - if(counter == 4) - { - DapLogMessage message; - message.setTimeStamp(list.at(0)); - message.setType(list.at(1)); - message.setFile(list.at(2)); - message.setMessage(list.at(3)); - DapLogModel::getInstance().append(message); - list.clear(); - counter = 0; - if(x != aNodeLogs.size()) - --x; - } - else if( x != aNodeLogs.size()) - { - list.append(aNodeLogs[x]); - ++counter; - } + const QStringList list = log.split(re); + DapLogMessage logMessage; + logMessage.setTimeStamp(list.at(0)); + logMessage.setType(list.at(1)); + logMessage.setFile(list.at(2)); + logMessage.setMessage(list.at(3)); + DapLogModel::getInstance().append(logMessage); } - emit logCompleted(); -} -void DapServiceController::get() -{ - clearLogModel(); - getNodeLogs(); + emit logCompleted(); } /// Get node logs. -/// @param aiTimeStamp Timestamp start reading logging. -/// @param aiRowCount Number of lines displayed. void DapServiceController::getNodeLogs() const { qInfo() << QString("getNodeLogs()"); diff --git a/CellFrameDashboardGUI/DapServiceController.h b/CellFrameDashboardGUI/DapServiceController.h index 36f5ba190101a5a0edc4de81da60f3cc6a9d5081..5dea5db29eb19f4502f34aae3458a31afd1abd4f 100755 --- a/CellFrameDashboardGUI/DapServiceController.h +++ b/CellFrameDashboardGUI/DapServiceController.h @@ -124,8 +124,6 @@ public slots: /// Change status of node /// @param it is true if a node is online void setNodeStatus(const bool aIsOnline); - /// - void get(); /// Get node logs. Q_INVOKABLE void getNodeLogs() const; diff --git a/CellFrameDashboardService/DapChainDashboardService.cpp b/CellFrameDashboardService/DapChainDashboardService.cpp index 836db4b3c864104eab2f4a1f1693c3ea10568554..afda918e8a011e232e1e9fec0f351d4407f11c2a 100755 --- a/CellFrameDashboardService/DapChainDashboardService.cpp +++ b/CellFrameDashboardService/DapChainDashboardService.cpp @@ -4,7 +4,6 @@ DapChainDashboardService::DapChainDashboardService() : DapRpcService(nullptr) { // Log reader m_pDapChainLogHandler = new DapChainLogHandler(this); - connect(m_pDapChainLogHandler, SIGNAL(onUpdateModel()), SLOT(clearLogModel())); connect(m_pDapChainLogHandler, SIGNAL(onChangedLog()), SLOT(changedLogModel())); m_pDapChainWalletHandler = new DapChainWalletHandler(this); connect(this, &DapChainDashboardService::onNewClientConnected, [=] { @@ -107,13 +106,6 @@ QString DapChainDashboardService::sendToken(const QString &asWalletName, const Q return m_pDapChainWalletHandler->sendToken(asWalletName, asReceiverAddr, asToken, asAmount); } -void DapChainDashboardService::clearLogModel() -{ - qDebug() << "clearLogModel()"; - QJsonArray arguments; - m_pServer->notifyConnectedClients("RPCClient.clearLogModel", arguments); -} - void DapChainDashboardService::changedLogModel() { qDebug() << "changedLogModel()"; diff --git a/CellFrameDashboardService/DapChainDashboardService.h b/CellFrameDashboardService/DapChainDashboardService.h index 4e4c0f9f0a9e76e2f3d1e2e5ae042722cbb00928..5d65d5dd4b13eef8b37f5e42868150b04908fce1 100755 --- a/CellFrameDashboardService/DapChainDashboardService.h +++ b/CellFrameDashboardService/DapChainDashboardService.h @@ -60,8 +60,6 @@ signals: void onNewClientConnected(); public slots: - void clearLogModel(); - void changedLogModel(); /// Activate the main client window by double-clicking the application icon in the system tray. /// @param reason Type of action on the icon in the system tray. diff --git a/CellFrameDashboardService/DapChainLogHandler.cpp b/CellFrameDashboardService/DapChainLogHandler.cpp index 809610d45a0a6ee894541db4ea0b857083f7c89d..6f5cbaae7c0d79df63c7f92030e3386124052fde 100755 --- a/CellFrameDashboardService/DapChainLogHandler.cpp +++ b/CellFrameDashboardService/DapChainLogHandler.cpp @@ -1,5 +1,7 @@ #include "DapChainLogHandler.h" +#include <QRegularExpression> + DapChainLogHandler::DapChainLogHandler(QObject *parent) : QObject(parent) { m_fileSystemWatcher.addPath(LOG_FILE); @@ -13,31 +15,31 @@ DapChainLogHandler::DapChainLogHandler(QObject *parent) : QObject(parent) QStringList DapChainLogHandler::request() { - /// TODO: The application doesn't work because of it. It needs to be changed -// QStringList m_listLogs; -// QFile file(LOG_FILE); -// if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) -// { -// emit onUpdateModel(); -// } -// else -// { -// QTextStream in(&file); -//// QRegExp rx("(\\[|\\]|\\s)([\\w*]{1,1}[\\w\\s\\W]+)([\\n]|\\])" ); !!! DO NOT DELETE!!! -// QRegExp rx("(\\[|\\]|\\s)([\\w*]{1,1}[\\w\\s\\W]+)(\\]|$)" ); -// rx.setMinimal(true); - - -// while (!in.atEnd()) { -// QString line = in.readLine(); -// int pos{0}; -// while((pos = rx.indexIn(line, pos)) != -1) -// { -// m_listLogs.append(rx.cap(2)); -// pos += rx.matchedLength(); -// } -// } -// } -// return m_listLogs; - return QStringList(); + QFile file(LOG_FILE); + if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) + { + qWarning() << "Failed to open file " << file.fileName(); + return QStringList(); + } + else + { + QTextStream in(&file); + in.seek(m_currentCaretPosition); + const QRegularExpression re("(\\[\\d\\d\\/\\d\\d\\/\\d\\d\\-\\d\\d\\:\\d\\d\\:\\d\\d])\\s(\\[\\w+\\])\\s(\\[\\w+\\])(.+)"); + + QStringList listLogs; + while (!in.atEnd()) { + const QString line = in.readLine(); + const auto match = re.match(line); + if(!match.hasMatch()) + continue; + + const QString matchedLog = match.captured(); + listLogs.append(matchedLog); + m_currentCaretPosition += matchedLog.length(); + } + + return listLogs; + + } } diff --git a/CellFrameDashboardService/DapChainLogHandler.h b/CellFrameDashboardService/DapChainLogHandler.h index 45453ca252d413eb090bc44c37be48be175cd68a..8f0fb75731bc36277a82051eff0bc258aed8760f 100644 --- a/CellFrameDashboardService/DapChainLogHandler.h +++ b/CellFrameDashboardService/DapChainLogHandler.h @@ -17,7 +17,8 @@ class DapChainLogHandler : public QObject /// Log file change watcher. QFileSystemWatcher m_fileSystemWatcher; - + /// Current caret position in log file + qint64 m_currentCaretPosition{0}; public: explicit DapChainLogHandler(QObject *parent = nullptr);