Index: sources/storage/Logger.h =================================================================== diff -u -rb043c5b9919a9a435e50907772ec8346823b05d6 -rfe30c662d0fdf9df32883c17772b5803b84d229e --- sources/storage/Logger.h (.../Logger.h) (revision b043c5b9919a9a435e50907772ec8346823b05d6) +++ sources/storage/Logger.h (.../Logger.h) (revision fe30c662d0fdf9df32883c17772b5803b84d229e) @@ -7,7 +7,7 @@ * * \file Logger.h * \author (last) Behrouz NematiPour - * \date (last) 06-Oct-2023 + * \date (last) 12-Mar-2024 * \author (original) Behrouz NematiPour * \date (original) 26-Aug-2020 * @@ -39,6 +39,7 @@ #define LOG_APPED_UI(vCONTENT) emit Storage::Logger::I().didLog(" ,UI," + vCONTENT, Storage::Logger::LogType::eLogAppED, true ) #define LOG_APPED_PO(vCONTENT) emit Storage::Logger::I().didLog("POST,UI," + vCONTENT, Storage::Logger::LogType::eLogAppED, true ) #define LOG_APPED_MSG(vID, vTEXT) LOG_APPED(QString("%1,%2").arg(QString("%1").arg(vID,4,16,QLatin1Char('0')).toUpper()).arg(vTEXT)) +#define LOG_APPED_CS(vCONTENT) emit Storage::Logger::I().didLog(" ,CS," + vCONTENT, Storage::Logger::LogType::eLogAppED, true ) // forward declarations class tst_logging; @@ -112,7 +113,7 @@ // 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. - // Initially + // NoRunning // Treatment // Disinfect // DisinfectHeat // later: the UI message needs to get updated and not using SubMode @@ -121,27 +122,31 @@ // DisinfectFlsh // later: the UI message needs to get updated and not using SubMode // "Disinfect" // "Treatment" - const char *_logFileNameMode_init = "NotRunnig"; + const char *_logFileNameMode_init = "NoRunning"; QString _logFileNameMode = "" ; QString _logFileNameDate = "" ; QString _logFileNameTime = "" ; - QHash _logPathNames; - const QHash _logBasePathNames { + 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 @@ -151,7 +156,7 @@ // !!!!!!!!!! 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 }, @@ -179,14 +184,59 @@ 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 ); + void didLogPathSet ( Logger::LogType vLogType, const QString &vLogPath ); + void didLogIOFail (); + void didLogBackup ( const QString vFileName ); + void didRetentionLogCS ( quint8 vPercent ); + public slots: bool init(); bool init(QThread &vThread);