Index: sources/storage/Logger.h =================================================================== diff -u -r84c5373209a1a488c00917995f5553d442d159a4 -r903697f659a275a5be31d05c460dae628f532aab --- sources/storage/Logger.h (.../Logger.h) (revision 84c5373209a1a488c00917995f5553d442d159a4) +++ sources/storage/Logger.h (.../Logger.h) (revision 903697f659a275a5be31d05c460dae628f532aab) @@ -7,9 +7,9 @@ * * \file Logger.h * \author (last) Behrouz NematiPour - * \date (last) 20-Aug-2020 + * \date (last) 12-Sep-2020 * \author (original) Behrouz NematiPour - * \date (original) 24-Sep-2019 + * \date (original) 26-Aug-2020 * */ #pragma once @@ -23,18 +23,21 @@ #include "main.h" // Doxygen : don't remove #include "StorageGlobals.h" - // Define #define _Logger Storage::Logger::I() #define LOG_EXPORT _Logger.concurrentExportLogs() +#define LOG_DEBUG(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogDebug, true ) -#define LOG_DEBUG(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogDebug) +#define ADD_EVENT_HEADER emit Storage::Logger::I().didLog(_headerE, Storage::Logger::LogType::eLogEvent, false) +#define LOG_EVENT(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogEvent, true ) +#define LOG_DATUM(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogDatum, true ) -#define LOG_EVENT(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogEvent) -#define LOG_DATUM(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogDatum) +#define MIXED_EVENT_DATUM +#undef DISABLE_ACKNOW_CHECKIN_MESSAGE_LOG + // forward declarations class tst_logging; @@ -82,17 +85,22 @@ eLogEvent, ///< Massages on the CANBus : Error is an event type eLogDatum, ///< Massages on the CANBus : Broadcast data type + eLogTrtmt, ///< Treatment Log Files + eLogType_Count, }; + Q_ENUM(LogType) private: + const char *_headerE = "TimeStamp,Type,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\r\n"; QDir _dir; QString _logFileNamePrefix; - QHash _logPathNames; + QHash _logPathNames; const QHash _logBasePathNames { { LogType::eLogEvent, "log/" }, { LogType::eLogDatum, "log/" }, { LogType::eLogDebug, "service/" }, + { LogType::eLogTrtmt, Storage::Treatment_Log_Folder }, }; const QHash _logPrefix { // Will be used for the logging in the file @@ -101,45 +109,63 @@ { LogType::eLogDebug, "" }, // it has its own file and all the content is Error }; - const QHash _logTypeName { // Will be used for for information - { LogType::eLogEvent, "Event" }, - { LogType::eLogDatum, "Datum" }, - { LogType::eLogDebug, "Error" }, // it has its own file and all the content is Error - }; - const QHash _logFileNameExt { { LogType::eLogEvent, ".log" }, +#ifdef MIXED_EVENT_DATUM { LogType::eLogDatum, ".log" }, +#else + { LogType::eLogDatum, ".dat" }, +#endif { LogType::eLogDebug, ".err" }, + { LogType::eLogTrtmt, ".log" }, }; - const QHash _logTypeExpiryDay { - { LogType::eLogEvent, 15 }, - { LogType::eLogDatum, 15 }, - { LogType::eLogDebug, 5 }, + // be careful when defining these percentages + // 1 - Since now both the Log and Datum are in the same place and file they have same percentage. + // if separated then the percentage has to be separated + // 2 - the total in _logTypeExpiryDay is not 100 and it has to be summed up with Storage::Available_Space_Percent. + // so it is 70% for Event/Datum + 15% Service + 15% free = 100% total + const QHash _logTypeMaxUsageLimit { +#ifdef MIXED_EVENT_DATUM + { LogType::eLogEvent, 70 }, // in percent + { LogType::eLogDatum, 70 }, // in percent +#else + { LogType::eLogEvent, 35 }, // in percent + { LogType::eLogDatum, 35 }, // in percent +#endif + { LogType::eLogDebug, 15 }, // in percent + // Not Sure yet so commented out in the remove. + { LogType::eLogTrtmt, 100}, // in percent // No Remove for now }; - const qint8 _availableSpacePercent = 25; // currently 16G SD-Card so 4G should always be available. + 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 *_dateFormat = "yyyy_MM_dd"; - const char *_timeFormat = "HH:mm:ss"; - - const char *_dateSeparator = "_"; // used in filename + const char *_dateSeparator = "_"; // used in filename const char *_separator = ","; - QString _logFileName = ""; + bool _enableConsoleOut = false; + QString _logFileName = ""; + QMutex _logRemoveRunning; + QFutureWatcher _exportLogsWatcher; QFutureWatcher _removeLogsWatcher; QThread *_thread = nullptr; bool _init = false; +public: + void enableConsoleOut(bool vEnabled); +signals: + void didLogPathSet(Logger::LogType vLogType, const QString &vLogPath); + public slots: bool init(); bool init(QThread &vThread); + private slots: void quit(); @@ -155,6 +181,8 @@ void setLogBasePath (bool vUseApplicationDirPath = false); bool setLogPath (); bool setLogPath (LogType vLogType); +public: + const QString &logPath(Logger::LogType vLogType); // ----- Export structure private : @@ -172,18 +200,24 @@ bool concurrentRemoveLogs(); void onRemoveLogs(); signals: - void didRemoveLogs(); + /*! + * \brief didRemoveLogs + * \details This signal will be emitted mainly for DriveWatcher to not to emit the signal that Logger is connected to + * , while the logging cleanup is in progress, otherwise if the log cleanup takes more that 1sec (current interval) + * in the DriveWatcher then the cleanup will be called again for no good reason. + * \param vInProgress - true if the log cleanup is in progress, false otherwise. + */ + void didRemoveLogs(bool vInProgress); // ----- Available space is low private slots: void onSDCardSpaceChange(bool vReady, qint64 vTotal, qint64 vAvailable, quint8 vPercent); - // ----- logging structure private slots: - void onLog (const QString &vContent, LogType vLogType); + void onLog (const QString &vContent, LogType vLogType, bool vTimestamp); private: - void log (const QString &vContent, LogType vLogType); + void log (const QString &vContent, LogType vLogType, bool vTimestamp); signals: /*! @@ -192,6 +226,6 @@ * \param vContent - content as type of string to be logged * \param vLogType - the type of logging of type Storage::Logger::LogType */ - void didLog (const QString &vContent, LogType vLogType); + void didLog (const QString &vContent, LogType vLogType, bool vTimestamp); }; }