Index: sources/storage/logger.cpp =================================================================== diff -u -r5e78f0799b46963feb5756decb1a27b952cd19b3 -r56d00a82669a7a2c00ab90109a89dbec8db27527 --- sources/storage/logger.cpp (.../logger.cpp) (revision 5e78f0799b46963feb5756decb1a27b952cd19b3) +++ sources/storage/logger.cpp (.../logger.cpp) (revision 56d00a82669a7a2c00ab90109a89dbec8db27527) @@ -24,31 +24,53 @@ // Project #include "storageglobals.h" #include "filehandler.h" +#include "threads.h" using namespace Storage; Logger::Logger(QObject *parent) : QObject(parent) { } +/*! + * \brief Logger::init + * \details Initializes the Class. + * \return False if it has been called before. + */ bool Logger::init() { + if ( _init ) return false; + _init = true; + // runs in main thread - Q_ASSERT_X(QThread::currentThread() == qApp->thread() , "_Logger::init", "The Class initialization must be done in Main Thread" ); + Q_ASSERT_X(QThread::currentThread() == qApp->thread() , __func__, "The Class initialization must be done in Main Thread" ); - // runs in Logger thread + // runs in thread checkLogPath(); - qRegisterMetaType("LogType"); initConnections(); return true; } +/*! + * \brief Logger::quit + * \details Does nothing for now + */ void Logger::quit() { } +/*! + * \brief Logger::initConnections + * \details Initializes the required signal/slot connection between this class and other objects + * to be able to communicate. + * \note No connection has been defined yet. + */ void Logger::initConnections() { } +/*! + * \brief Logger::checkLogPath + * \details Sets the log paths and creates them if didn't exist. + */ void Logger::checkLogPath() { setLogBasePath(); // try to use /media/sd_card on device @@ -58,6 +80,13 @@ } } +/*! + * \brief Logger::setLogBasePath + * \details Tries to the set the log path to the default log path (Log_Base_Path_Name) + * Will set the application folder as the base log path if can't set the log path to the default. + * Will log the event in that case. + * \param vUseApplicationDirPath + */ void Logger::setLogBasePath(bool vUseApplicationDirPath) { if (vUseApplicationDirPath) { @@ -68,6 +97,11 @@ } } +/*! + * \brief Logger::setLogPath + * \details set the log path for each of the Datum, Event, Error log types + * \return False if can not st the log paths. + */ bool Logger::setLogPath() { bool ok = true; @@ -77,6 +111,13 @@ return ok; } +/*! + * \brief Logger::setLogPath + * \details Sets the log path for the log type vLogType + * Creates the folder if not exists. + * \param vLogType - log type + * \return returns false if the path doesn't exist and folder can't be created. + */ bool Logger::setLogPath(LogType vLogType) { _logPathNames[vLogType] = _dir.path() + "/" + _logBasePathNames[vLogType]; @@ -92,10 +133,16 @@ return true; } +/*! + * \brief Logger::log + * \details Logs the content vContent in log type of vLogType. + * \param vContent - Log content + * \param vLogType - Log type + * \note This method is not thread-safe so is private and needs to be called by concurrentLog + * Which uses QtConcurrent::run to run in thread and thread-safe. + */ void Logger::log(const QString &vContent, Logger::LogType vLogType) { - PRINT_THREAD_NAME; - QString date = QDate::currentDate().toString(_dateFormat); QString mContent; @@ -118,9 +165,15 @@ } } +/*! + * \brief Logger::concurrentLog + * \details The thread safe of calling the log method in a separate thread. + * This method uses the QtConcurrent::run to call the log in separate thread and thread-safe. + * \param vContent - the content to be logged + * \param vLogType - The log type + */ void Logger::concurrentLog(const QString &vContent, LogType vLogType) { - PRINT_THREAD_NAME; // QFuture future = QtConcurrent::run(this,&Logger::log, vContent, vLogType); // qDebug() << future.result();