Index: sources/storage/Logger.h =================================================================== diff -u -ra76eeb1808fb6012897a86d2d7f318dda85773b4 -r8566686e033eaa3025180a735ce6f485e4fcaad4 --- sources/storage/Logger.h (.../Logger.h) (revision a76eeb1808fb6012897a86d2d7f318dda85773b4) +++ sources/storage/Logger.h (.../Logger.h) (revision 8566686e033eaa3025180a735ce6f485e4fcaad4) @@ -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.h * \author (last) Behrouz NematiPour - * \date (last) 14-Aug-2023 + * \date (last) 06-Oct-2023 * \author (original) Behrouz NematiPour * \date (original) 26-Aug-2020 * @@ -43,6 +43,8 @@ // forward declarations class tst_logging; +using namespace Gui; + namespace Storage { /*! @@ -101,23 +103,49 @@ const char *_headerA = "TimeStamp,ID,SubSys,Name,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40"; const char *_headerD = "TimeStamp,Description"; QDir _dir; - QString _logFileNamePrefix; - QHash _logPathNames; - const QHash _logBasePathNames { + + // The HSSerial is going to be the HD Serial always, + // but while booting the logger is initialized first before the HD sends its serial number. + // therefore during the bootup and POST that we don't have the serial, will use BootPOST. + QString _logFileNameHDSN = "BootPOST" ; + + // The Mode is the device main states comming from HD_OpMode + // this is not exactly the HD_OpModes and will be interpreted in desired cycles. + // At the moment we decided to have Standby, Treatment, Disinfection, and I am adding Initial as well. + // NoRunning + // Treatment + // Disinfect + // DisinfectHeat // later: the UI message needs to get updated and not using SubMode + // DisinfectChem // later: the UI message needs to get updated and not using SubMode + // DisinfectChemFlsh // later: the UI message needs to get updated and not using SubMode + // DisinfectFlsh // later: the UI message needs to get updated and not using SubMode + // "Disinfect" + // "Treatment" + const char *_logFileNameMode_init = "NoRunning"; + QString _logFileNameMode = "" ; + QString _logFileNameDate = "" ; + QString _logFileNameTime = "" ; + + typedef QHash TLogData; + typedef QHash TLogMaxUse; + + TLogData _logPathNames; + const TLogData _logBasePathNames { { LogType::eLogAppED, Storage::Log_Folder_Application}, { LogType::eLogDebug, Storage::Log_Folder_Service }, { LogType::eLogCloud, Storage::Log_Folder_CloudSync }, { LogType::eLogTrtmt, Storage::Txr_Folder_Treatment }, }; - const QHash _logNames { // Will be used for the logging in the file + const TLogData _logNames { // Will be used for the logging in the file { LogType::eLogAppED, "Log" }, { LogType::eLogDebug, "Service" }, { LogType::eLogCloud, "Cloud" }, { LogType::eLogTrtmt, "Treatment" }, }; - const QHash _logFileNameExt { + const char * _logFileNamePendingSubExt = "u."; + const TLogData _logFileNameExt { { LogType::eLogAppED, ".log" }, // Application log { LogType::eLogDebug, ".err" }, // Application error { LogType::eLogCloud, ".log" }, // CloudSync debug @@ -127,19 +155,21 @@ // !!!!!!!!!! IMPORTANT !!!!!!!!!! // be careful with these percentages // please refer to the Storage namespace. - const QHash _logTypeMaxUsageLimit { + const TLogMaxUse _logTypeMaxUsageLimit { { LogType::eLogAppED, Storage::Log_Max_Allowable_AppED_Space_Percent }, { LogType::eLogDebug, Storage::Log_Max_Allowable_Debug_Space_Percent }, { LogType::eLogCloud, Storage::Log_Max_Allowable_Cloud_Space_Percent }, { LogType::eLogTrtmt, Storage::Txr_Max_Allowable_Trtmt_Space_Percent }, }; - const char *_dateFormat = "yyyy_MM_dd" ; // date used in the file name - const char *_timeFormat = "HH:mm:ss.zzz"; // timestamp in the file + const char *_fileDateFormat = "yyyyMMdd" ; // date used in the file name + const char *_fileTimeFormat = "HHmmss" ; // timestamp in the file - const char *_dateSeparator = "_"; // used in filename - const char *_separator = ","; + const char *_timeFormat = "HH:mm:ss.zzz"; // timestamp in the file + const char *_fileSeparator = "_"; // used in filename + const char *_separator = ","; + bool _enableConsoleOut = false; QString _logFileName = ""; @@ -153,12 +183,56 @@ bool _init = false; public: + QString logFileNamePendingSubExt() { + return _logFileNamePendingSubExt; + } + + QString logFileNameExt ( LogType vLogType ) { + return _logFileNameExt[vLogType]; + } + + QString logPathName(LogType vLogType) { + return _logPathNames[vLogType]; + } + + /*! + * \brief logFileNameExt_AD + * \details Finds the type of the log by log file extention. + * \note Since the log file ext of the cloud and UI are the same, this finction will ignore the eLogCloud and will return eLogAppED type instead. + * \param vLogExt - the log file extention. + * \return + */ + LogType logFileNameExt_AD ( const QString &vLogExt ) { + if ( _logFileNameExt.values().contains(vLogExt) ) { + LogType logType = _logFileNameExt.key(vLogExt); + if ( logType == eLogCloud) logType = eLogAppED; + return logType; + } + return eLogNone; + } + + LogType logFileLogType (const QString &vFileName, QString &vFilePath) { + QFileInfo fileInfo(vFileName); + QString ext = fileInfo.suffix(); + LogType logType = logFileNameExt_AD("." + ext); + QString logFilePath; + if ( logType != eLogNone ) { + logFilePath = Log_Folder_Base + _logBasePathNames[logType]; + } + if ( fileInfo.exists(logFilePath + vFileName) ) { + vFilePath = logFilePath; + return logType; + } + return eLogNone; + } +public: void enableConsoleOut(bool vEnabled); void postInit(); signals: void didLogPathSet(Logger::LogType vLogType, const QString &vLogPath); void didLogIOFail(); + void didLogBackup ( const QString vFileName ); public slots: bool init(); @@ -184,16 +258,18 @@ // ----- Export structure private : - bool exportList(const Gui::GuiStringIndexMap &vExportList, LogType vLogType); - bool exportLogs(const Gui::GuiStringIndexMap &vExportList); - bool exportErrs(const Gui::GuiStringIndexMap &vExportList); - bool exportTrts(const Gui::GuiStringIndexMap &vExportList); + bool exportList (const GuiStringIndexMap &vExportList, LogType vLogType); + bool exportLogs (const GuiStringIndexMap &vExportList); + bool exportErrs (const GuiStringIndexMap &vExportList); + bool exportTrts (const GuiStringIndexMap &vExportList); + public slots: // this slot is thread safe and can be called from outside by LOG_EXPORT. bool concurrentExportIsOk (); - bool concurrentExportLogs (const Gui::GuiStringIndexMap &vExportList); - bool concurrentExportErrs (const Gui::GuiStringIndexMap &vExportList); - bool concurrentExportTrts (const Gui::GuiStringIndexMap &vExportList); + bool concurrentExportLogs (const GuiStringIndexMap &vExportList); + bool concurrentExportErrs (const GuiStringIndexMap &vExportList); + bool concurrentExportTrts (const GuiStringIndexMap &vExportList); void onExportLogs (); + signals: void didExportLogs(); void didExportStat(quint32 vIndex, const QString &vFileName, quint8 vPercent); @@ -205,6 +281,7 @@ bool concurrentRemoveLogs(LogType vLogType = eLogFiles); void onRemoveLogs(); void onCryptSetupMount (bool vPass); + void onActionReceive (GuiActionType vAction, const QVariantList &vData); signals: /*!