Index: sources/storage/logger.h =================================================================== diff -u -r44a85c96ab55e424866ec4cca0270aa218355f82 -rd2035a8728794afeefaa244bf8d1597926d945f5 --- sources/storage/logger.h (.../logger.h) (revision 44a85c96ab55e424866ec4cca0270aa218355f82) +++ sources/storage/logger.h (.../logger.h) (revision d2035a8728794afeefaa244bf8d1597926d945f5) @@ -27,39 +27,14 @@ // Define #define _Logger Storage::Logger::I() -#define LOG_EXPORT _Logger.concurrentExport() +#define LOG_EXPORT _Logger.concurrentExportLogs() -#define LOG_EVENT(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogEvent) -#define LOG_EVENT_ONCE_LOGGED \ - bLOG_EVENT_ONCE_LOGGED -#define LOG_EVENT_ONCE(vCONTENT) \ - static bool LOG_EVENT_ONCE_LOGGED = false; \ - if ( ! LOG_EVENT_ONCE_LOGGED ) { \ - LOG_EVENT_ONCE_LOGGED = true; \ - LOG_EVENT(vCONTENT); \ - } -#define LOG_ERROR(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogError) -#define LOG_ERROR_ONCE_LOGGED \ - bLOG_ERROR_ONCE_LOGGED -#define LOG_ERROR_ONCE(vCONTENT) \ - static bool LOG_ERROR_ONCE_LOGGED = false; \ - if ( ! LOG_ERROR_ONCE_LOGGED ) { \ - LOG_ERROR_ONCE_LOGGED = true; \ - LOG_ERROR(vCONTENT); \ - } +#define LOG_DEBUG(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogDebug) -#define LOG_DATUM(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogDatum) -#define LOG_DATUM_ONCE_LOGGED \ - bLOG_DATUM_ONCE_LOGGED -#define LOG_DATUM_ONCE(vCONTENT) \ - static bool LOG_DATUM_ONCE_LOGGED = false; \ - if ( ! LOG_DATUM_ONCE_LOGGED ) { \ - LOG_DATUM_ONCE_LOGGED = true; \ - LOG_DATUM(vCONTENT); \ - } +#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) - // forward declarations class tst_logging; @@ -68,14 +43,14 @@ /*! * \brief The Logger class * \details Main logger class that has all the required implementation for logging. - * The provided interface is the LOG_DATUM, LOG_EVENT, LOG_ERROR, LOG_EXPORT defines + * The provided interface is the LOG_DATUM, LOG_EVENT, LOG_DEBUG, LOG_EXPORT defines * and no other methods. * This should have its own thread. * \note * PLEASE BE CAREFUL THIS CLASS IS USING QtConcurrent::run FOR THE EXPORT LOG FILES. * AND ONLY PRIVATE VOID LOG (,) IS CALLING IN POOLED THREAD * PLEASE BE VERY CAREFUL. - * ALL THE OTHER CLASSES TO USE THIS CLASS SHOULD ONLY USE LOG_DATUM, LOG_EVENT, LOG_ERROR + * ALL THE OTHER CLASSES TO USE THIS CLASS SHOULD ONLY USE LOG_DATUM, LOG_EVENT, LOG_DEBUG * TO DO THE LOGGING */ class Logger : public QObject @@ -85,39 +60,58 @@ // friends friend class ::tst_logging; -public: +public : enum LogType { - eLogEvent, - eLogError, - eLogDatum, + eLogDebug, ///< Application Error : CANBus messages doesn't have error it's Evnet/Data only + eLogEvent, ///< Massages on the CANBus : Error is an event type + eLogDatum, ///< Massages on the CANBus : Broadcast data type + eLogType_Count, - }; + }; private: - QDir _dir; + QDir _dir; + QString _logFileNamePrefix; QHash _logPathNames; - QHash _logBasePathNames { - { eLogEvent, "log/event/" }, - { eLogError, "log/error/" }, - { eLogDatum, "log/event/" }, // "log/datum/" + const QHash _logBasePathNames { + { LogType::eLogEvent, "log/" }, + { LogType::eLogDatum, "log/" }, + { LogType::eLogDebug, "service/" }, }; - QHash _logPrefix { - { eLogEvent, "Event" }, - { eLogError, "Error" }, - { eLogDatum, "Datum" }, + const QHash _logPrefix { // Will be used for the logging in the file + { LogType::eLogEvent, "E" }, + { LogType::eLogDatum, "D" }, + { 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" }, + { LogType::eLogDatum, ".log" }, + { LogType::eLogDebug, ".err" }, + }; + const QHash _logTypeExpiryDay { + { LogType::eLogEvent, 15 }, + { LogType::eLogDatum, 15 }, + { LogType::eLogDebug, 5 }, + }; + const qint8 _availableSpacePercent = 25; // currently 16G SD-Card so 4G should always be available. + const char *_dateFormat = "yyyy_MM_dd"; const char *_timeFormat = "HH:mm:ss"; - const char *_prefixSeparator = ": " ; - const char *_dateSeparator = "_" ; - const char *_timeSeparator = " , "; + const char *_dateSeparator = "_"; // used in filename + const char *_separator = ","; QString _logFileName = ""; - QFutureWatcher _exportWatcher; + QFutureWatcher _exportLogsWatcher; + QFutureWatcher _removeLogsWatcher; QThread *_thread = nullptr; bool _init = false; @@ -146,22 +140,34 @@ bool setLogPath (LogType vLogType); // ----- Export structure -public slots: - bool concurrentExport(); -private slots: - void onExport(); +private : + bool exportLogs(); +public slots: // this slot is thread safe and can be called from outside by LOG_EXPORT. + bool concurrentExportLogs(); + void onExportLogs(); signals: - /*! - * \brief didExport - * \details notifies the UI when the export is done. - */ - void didExport(); + void didExportLogs(); +// ----- Remove Old Logs structure +private: + int removeLogs(); +private slots: // this slot is thread safe and can be called from outside but preffered not to. + bool concurrentRemoveLogs(); + void onRemoveLogs(); +signals: + void didRemoveLogs(); + +// ----- 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); private: void log (const QString &vContent, LogType vLogType); + signals: /*! * \brief didLog