Index: sources/storage/Logger.cpp =================================================================== diff -u -r5bb4a64727ce89d613ab0b79813b1a3f768291ff -ra35d996679eec8aad3085ee095d631dde2013361 --- sources/storage/Logger.cpp (.../Logger.cpp) (revision 5bb4a64727ce89d613ab0b79813b1a3f768291ff) +++ sources/storage/Logger.cpp (.../Logger.cpp) (revision a35d996679eec8aad3085ee095d631dde2013361) @@ -1,13 +1,13 @@ /*! * - * Copyright (c) 2020-2023 Diality Inc. - All Rights Reserved. + * Copyright (c) 2020-2024 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file Logger.cpp * \author (last) Behrouz NematiPour - * \date (last) 21-Aug-2023 + * \date (last) 08-Apr-2024 * \author (original) Behrouz NematiPour * \date (original) 26-Aug-2020 * @@ -24,6 +24,7 @@ #include // Project +#include "ApplicationController.h" #include "DeviceController.h" #include "Threads.h" #include "StorageGlobals.h" @@ -40,7 +41,9 @@ * Qt handles the children destruction by their parent objects life-cycle. */ Logger::Logger(QObject *parent) : QObject(parent) { - _logFileNamePrefix = QFileInfo(qApp->applicationFilePath()).baseName(); + if ( ! ( gLogLongName || gLogSerialName ) ) { + _fileDateFormat = "yyyy_MM_dd"; // date used in the file name + } } /*! @@ -130,6 +133,9 @@ */ void Logger::initConnections() { + connect(&_ApplicationController , SIGNAL(didActionReceive (GuiActionType , const QVariantList &)), + this , SLOT( onActionReceive (GuiActionType , const QVariantList &))); + connect(&_exportLogsWatcher, SIGNAL(finished ()), this , SLOT(onExportLogs())); @@ -234,7 +240,7 @@ #endif if (vUseTempPath) { - _dir.setPath(Storage::Standard_tmp); + _dir.setPath(gStandard_tmp); // NOTE: Do not use LOG_XXXXX, At this moment Logger has not been initialized yet QString msg = QString("temp location used for events logging (%1)").arg(_dir.path()); //DEBUG qDebug() << msg; @@ -271,8 +277,8 @@ QString basePath = Storage::Settings_Path(); // use the Settings path first (/var/configurations (Encrypted Partition)) - if ( ! QDir (basePath ).exists( )) { basePath = Storage::Standard_tmp; goto lOut; } - if ( ! FileHandler::makeFolder (basePath + Storage::Txr_Folder_Treatment )) { basePath = Storage::Standard_tmp; goto lOut; } + if ( ! QDir (basePath ).exists( )) { basePath = gStandard_tmp; goto lOut; } + if ( ! FileHandler::makeFolder (basePath + Storage::Txr_Folder_Treatment )) { basePath = gStandard_tmp; goto lOut; } lOut: _logPathNames[vLogType] = basePath + Storage::Txr_Folder_Treatment; @@ -313,13 +319,13 @@ { if ( ! checkThread() ) return; - static QString date; QString mContent; // - Add header - QString currentDate = QDate::currentDate().toString(_dateFormat); - if ( date != currentDate ) { - if ( ! date.isEmpty() ) { + QString currentDate = QDate::currentDate().toString(_fileDateFormat); + QString currentTime = QTime::currentTime().toString(_fileTimeFormat); + if ( _logFileNameDate != currentDate ) { + if ( ! _logFileNameDate.isEmpty() ) { switch ( vLogType ) { case eLogAppED : mContent = _headerA; break; case eLogDebug : mContent = _headerD; break; @@ -328,17 +334,69 @@ } mContent += "\r\n"; } - date = currentDate; + _logFileNameDate = currentDate; + _logFileNameTime = currentTime; } // - Make log file name - QString fileName = date + _dateSeparator + _logFileNamePrefix; + if (_logFileNameMode.isEmpty()) { + _logFileNameMode = _logFileNameMode_init; + } + + QString fileName; + if ( gLogLongName ) { // -x + fileName = _logFileNameHDSN + + _fileSeparator + _logFileNameDate + + _fileSeparator + _logFileNameTime + + _fileSeparator + _logFileNameMode + ; + } + else + if ( gLogSerialName ) { // -X + fileName = _logFileNameHDSN + + _fileSeparator + _logFileNameDate + ; + } + else { + fileName = _logFileNameDate + + _fileSeparator + Storage::systemSetupPostfix; + } + + + + + // case LogType::eLogTrtmt: // this type of log will never happen here. Only put here to make sure it is intentional. switch (vLogType) { - case LogType::eLogAppED: - case LogType::eLogDebug: - // case LogType::eLogTrtmt: // this type of log will never happen here. Only put here to make sure it is intentional. - fileName += _logFileNameExt[vLogType]; + case LogType::eLogAppED: { + // ------------------------------------------------------------------------ TODO: Improve : function declaration + fileName += _logFileNameExt[vLogType]; + static QString oFileName; + if( oFileName != fileName ) { + if( oFileName.trimmed().isEmpty() ) { + oFileName = fileName; + } + else { + emit didLogBackup( _logPathNames[vLogType] + oFileName ); + oFileName = fileName; + } + } + } break; + case LogType::eLogDebug: { + // ------------------------------------------------------------------------ TODO: Improve : function declaration + fileName += _logFileNameExt[vLogType]; + static QString oFileName; + if( oFileName != fileName ) { + if( oFileName.trimmed().isEmpty() ) { + oFileName = fileName; + } + else { + emit didLogBackup( _logPathNames[vLogType] + oFileName ); + oFileName = fileName; + } + } + } + break; default: fileName += _logFileNameExt[eLogDebug]; @@ -375,7 +433,7 @@ * into USB drive folder (Storage::USB_Mount_Point) * \return true if at least one file has been exported */ -bool Logger::exportLogs(const Gui::GuiStringIndexMap &vExportList) +bool Logger::exportLogs(const GuiStringIndexMap &vExportList) { return exportList(vExportList, eLogAppED); } @@ -386,7 +444,7 @@ * into USB drive folder (Storage::USB_Mount_Point) * \return true if at least one file has been exported */ -bool Logger::exportErrs(const Gui::GuiStringIndexMap &vExportList) +bool Logger::exportErrs(const GuiStringIndexMap &vExportList) { return exportList(vExportList, eLogDebug); } @@ -397,7 +455,7 @@ * into USB drive folder (Storage::USB_Mount_Point) * \return true if at least one file has been exported */ -bool Logger::exportTrts(const Gui::GuiStringIndexMap &vExportList) +bool Logger::exportTrts(const GuiStringIndexMap &vExportList) { return exportList(vExportList, eLogTrtmt); } @@ -422,7 +480,7 @@ * \return always returns true for now. * \note This method uses QtConcurrent run to execute the FileHandler copyFolder method. */ -bool Logger::concurrentExportLogs(const Gui::GuiStringIndexMap &vExportList) +bool Logger::concurrentExportLogs(const GuiStringIndexMap &vExportList) { if ( ! concurrentExportIsOk() ) return false; @@ -439,7 +497,7 @@ * \return always returns true for now. * \note This method uses QtConcurrent run to execute the FileHandler copyFolder method. */ -bool Logger::concurrentExportErrs(const Gui::GuiStringIndexMap &vExportList) +bool Logger::concurrentExportErrs(const GuiStringIndexMap &vExportList) { if ( ! concurrentExportIsOk() ) return false; @@ -456,7 +514,7 @@ * \return always returns true for now. * \note This method uses QtConcurrent run to execute the FileHandler copyFolder method. */ -bool Logger::concurrentExportTrts(const Gui::GuiStringIndexMap &vExportList) +bool Logger::concurrentExportTrts(const GuiStringIndexMap &vExportList) { if ( ! concurrentExportIsOk() ) return false; @@ -487,6 +545,75 @@ // disabled coco end /*! + * \brief CloudSyncController::onActionReceive + * \details The slot which will be called when a CANBus message is received, and will be sent to CloudSync if related. + * \param vAction - The message action + * \param vData - The message data + */ +void Logger::onActionReceive(GuiActionType vAction, const QVariantList &vData) +{ + switch (vAction) { + case GuiActionType::ID_HDOperationModeData : { + if ( vData.length() >= 2 ) { + bool ok = true; + quint32 opMode = vData[0].toUInt(&ok); if ( ! ok ) return; + quint32 subMode = vData[1].toUInt(&ok); if ( ! ok ) return; + QString mode; + if ( opMode == GuiHDOpModes::MODE_STAN && subMode >= GuiHDStandbyStates::STANDBY_WAIT_FOR_DISINFECT_STATE ) { + mode = "Disinfect"; + if( _logFileNameMode != mode ) { + _logFileNameMode = mode; + _logFileNameTime = QDateTime::currentDateTime().time().toString(_fileTimeFormat); + } + } + else { + switch ( opMode ) { + case GuiHDOpModes::MODE_NLEG: + case GuiHDOpModes::MODE_FAUL: + case GuiHDOpModes::MODE_SERV: + case GuiHDOpModes::MODE_INIT: + case GuiHDOpModes::MODE_STAN: + mode = _logFileNameMode_init; + if( _logFileNameMode != mode ) { + _logFileNameMode = mode; + _logFileNameTime = QDateTime::currentDateTime().time().toString(_fileTimeFormat); + } + break; + case GuiHDOpModes::MODE_TPAR: + case GuiHDOpModes::MODE_PRET: + case GuiHDOpModes::MODE_TREA: + case GuiHDOpModes::MODE_POST: + mode = "Treatment"; + if( _logFileNameMode != mode ) { + _logFileNameMode = mode; + _logFileNameTime = QDateTime::currentDateTime().time().toString(_fileTimeFormat); + } + break; + + default: + break; + } + break; + } + } + } + break; + + case GuiActionType::ID_AdjustSerialHDRsp : { + if ( vData.length() >= 1 ) { + QString hdSerial= vData[0].toString(); + if ( hdSerial.trimmed().isEmpty() ) hdSerial = "Unknown"; + _logFileNameHDSN = hdSerial; + } + } + break; + + default: + break; + } +} + +/*! * \brief Logger::removeLogs * \details Remove old logs by iterating in the log/service folders and look for expired logs. * \return count file(s) have been removed. @@ -501,6 +628,11 @@ auto logFile = { vLogType }; // Is mostly used for the txr files which are in separate partition. for ( const auto &iType : ( vLogType == eLogFiles ? logFiles : logFile ) ) { + // The Application does not have access to remove the CloudSync logs, + // therefore sends CloudSync a message with expected used percent of the log files, + // to remove the logs. + if ( iType == eLogCloud ) { emit didRetentionLogCS(_logTypeMaxUsageLimit[iType]); continue; } + QString mCSource = _logPathNames [iType]; QString mCExtension = _logFileNameExt[iType]; // DEBUG: qDebug() << "@" << mCSource << mLogFileFilter << mCExtension << iType << _logTypeMaxUsageLimit[iType]; @@ -679,7 +811,7 @@ * \param vLogType - type of the log files to get the correct location for export. * \return true if the export is successful. */ -bool Logger::exportList(const Gui::GuiStringIndexMap &vExportList, Logger::LogType vLogType) +bool Logger::exportList(const GuiStringIndexMap &vExportList, Logger::LogType vLogType) { // DEBUG: qDebug() << __FUNCTION__ << vExportList; // qDebug() << " ~~~~~~~~~~ " << QThread::currentThread()->objectName(); @@ -697,7 +829,7 @@ result = FileHandler::copyFolder( mSource, mDestination); } else { - Gui::GuiStringIndexMapIterator it(vExportList); + GuiStringIndexMapIterator it(vExportList); while ( it.hasNext() ) { it.next(); // qDebug() << it.key() << it.value() << mSource << mDestination;