Index: sources/storage/logger.h =================================================================== diff -u -r781e62c996e81897517fbdb1bc79fe3bbcf165c1 -r415f3e16ff6e572c8ce7e7b3576e82ce8b44c6ce --- sources/storage/logger.h (.../logger.h) (revision 781e62c996e81897517fbdb1bc79fe3bbcf165c1) +++ sources/storage/logger.h (.../logger.h) (revision 415f3e16ff6e572c8ce7e7b3576e82ce8b44c6ce) @@ -13,19 +13,132 @@ */ #pragma once +// Qt #include +#include +#include +// Project +#include "main.h" +#include "storageglobals.h" + + +// Define +#define _Logger Storage::Logger::I() +#define LOG_EVENT(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogEvent) +#define LOG_ERROR(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogError) +#define LOG_DATUM(vCONTENT) emit Storage::Logger::I().didLog(vCONTENT, Storage::Logger::LogType::eLogDatum) +#define LOG_EXPORT _Logger.concurrentExport() + +// forward declarations +class tst_logging; + namespace Storage { +/*! + * \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 + * and no other methods. + * This should have it's 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 + * TO DO THE LOGGING + */ class Logger : public QObject { Q_OBJECT + + // friends + friend class ::tst_logging; + public: - explicit Logger(QObject *parent = nullptr); + enum LogType { + eLogEvent, + eLogError, + eLogDatum, + }; -signals: +private: + QDir _dir; + QHash _logPathNames; + QHash _logBasePathNames { + { eLogEvent, "log/event/" }, + { eLogError, "log/error/" }, + { eLogDatum, "log/event/" }, // "log/datum/" + }; + QHash _logPrefix { + { eLogEvent, "Event" }, + { eLogError, "Error" }, + { eLogDatum, "Datum" }, + }; + const char *_dateFormat = "yyyy_MM_dd"; + const char *_timeFormat = "HH:mm:ss"; + + const char *_prefixSeparator = ": " ; + const char *_dateSeparator = "_" ; + const char *_timeSeparator = " , "; + + QString _logFileName = ""; + + QFutureWatcher _exportWatcher; + + QThread *_thread = nullptr; + bool _init = false; + +// Singleton +SINGLETON(Logger) + public slots: + bool init(); + bool init(QThread &vThread); + +private slots: + void quit(); + +private: + void initConnections(); + + void initThread(QThread &vThread); + void quitThread(); + +private: +// ----- setting up + void checkLogPath (); + void setLogBasePath (bool vUseApplicationDirPath = false); + bool setLogPath (); + bool setLogPath (LogType vLogType); + +// ----- Export structure +public slots: + bool concurrentExport(); +private slots: + void onExport(); +signals: + /*! + * \brief didExport + * \details notifies the UI when the export is done. + */ + void didExport(); + +// ----- logging structure +private slots: + void onLog(const QString &vContent, LogType vLogType); +private: + void log (const QString &vContent, LogType vLogType); +signals: + /*! + * \brief didLog + * \details Notifies the logger on a request for log + * \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); }; } +