Index: sources/storage/Logger.cpp =================================================================== diff -u -raccc25a2cefe436401ad04c57713cfa410621317 -re6ddf6840cdd5a09deaac1dcdcd7d70064dc6a09 --- sources/storage/Logger.cpp (.../Logger.cpp) (revision accc25a2cefe436401ad04c57713cfa410621317) +++ sources/storage/Logger.cpp (.../Logger.cpp) (revision e6ddf6840cdd5a09deaac1dcdcd7d70064dc6a09) @@ -155,8 +155,10 @@ connect(&_removeLogsWatcher, SIGNAL(finished ()), this , SLOT(onRemoveLogs())); - connect(&_flushLogsWatcher , SIGNAL(finished ()), - this , SLOT(onFlushLogs())); + connect(&_flushLogsWatcherA, SIGNAL(finished ()), + this , SLOT(onFlushLogsA())); + connect(&_flushLogsWatcherD, SIGNAL(finished ()), + this , SLOT(onFlushLogsD())); connect(&_DeviceController, SIGNAL( didSDCardStateChange(bool, bool)), this , SLOT( onSDCardStateChange(bool, bool))); @@ -321,10 +323,10 @@ _cacheCounter --; } else { - _cacheCounter = _cachetimeout; _cacheIndex = logSwitch(); // switch the index for caching while the flush is working - concurrentFlushLog(eLogAppED); - concurrentFlushLog(eLogDebug); + concurrentFlushLogA(); + concurrentFlushLogD(); + _cacheCounter = _cachetimeout; } } @@ -336,7 +338,7 @@ } } -Logger::CacheIndex Logger::logSwitch() { +int Logger::logSwitch() { return _cacheIndex == eCache1 ? eCache2 : eCache1;; } @@ -367,12 +369,16 @@ case eLogAppED : _cacheA[_cacheIndex] += mContent; break; case eLogDebug : _cacheD[_cacheIndex] += mContent; break; default : _cacheD[_cacheIndex] += QString("Incorrect type of logging %1").arg(vLogType); - _cacheD[_cacheIndex] += mContent; + _cacheD[_cacheIndex] += mContent; break; } if ( logOverflow(vLogType) ) { _cacheIndex = logSwitch(); // switch the index for caching while the flush is working - concurrentFlushLog(vLogType); + switch ( vLogType ) { + case eLogAppED : concurrentFlushLogA(); break; + case eLogDebug : concurrentFlushLogD(); break; + default : concurrentFlushLogD(); break; + } } // console out the log if enabled. @@ -396,7 +402,7 @@ //NOTE: the _cacheIndex has been (has to be) switched for the log to continue while we are in the temp thread to flush the log - CacheIndex cacheIndex = logSwitch(); + QAtomicInt cacheIndex = logSwitch(); QString mContent; QDateTime datetime = QDateTime::currentDateTime(); int count = 0; @@ -498,26 +504,53 @@ * \return always returns true for now. * \note This method uses QtConcurrent to execute the flush method in a separate temp thread. */ -bool Logger::concurrentFlushLog(LogType vLogType) +bool Logger::concurrentFlushLogA() { - emit didFlushLogs(true); - LOG_DEBUG("Flush Logs Starting"); - QFuture mFuture = QtConcurrent::run(this, &Logger::flush, vLogType); - _flushLogsWatcher.setFuture(mFuture); + emit didFlushLogsA(true); + _flushElapsedA.start(); + LOG_DEBUG("Flush app Logs Starting"); + QFuture mFuture = QtConcurrent::run(this, &Logger::flush, LogType::eLogAppED); + _flushLogsWatcherA.setFuture(mFuture); return true; } /*! + * \brief Logger::concurrentFlushLogs + * \details Flushes the log buffer to the file in a separate thread + * \return always returns true for now. + * \note This method uses QtConcurrent to execute the flush method in a separate temp thread. + */ +bool Logger::concurrentFlushLogD() +{ + emit didFlushLogsD(true); + _flushElapsedD.start(); + LOG_DEBUG("Flush err Logs Starting"); + QFuture mFuture = QtConcurrent::run(this, &Logger::flush, LogType::eLogDebug); + _flushLogsWatcherD.setFuture(mFuture); + return true; +} + +/*! * \brief Logger::onRemoveLogs * \details Remove old logs notification slot which logs result of remove. */ -void Logger::onFlushLogs() +void Logger::onFlushLogsA() { - LOG_DEBUG(tr("Flush Logs Ended: %1").arg(_flushLogsWatcher.result())); - emit didFlushLogs(false); + LOG_DEBUG(tr("Flush app Logs Ended: %1,%2").arg(_flushLogsWatcherA.result()).arg(_flushElapsedA.elapsed())); + emit didFlushLogsA(false); } /*! + * \brief Logger::onRemoveLogs + * \details Remove old logs notification slot which logs result of remove. + */ +void Logger::onFlushLogsD() +{ + LOG_DEBUG(tr("Flush err Logs Ended: %1,%2").arg(_flushLogsWatcherD.result()).arg(_flushElapsedD.elapsed())); + emit didFlushLogsD(false); +} + +/*! * \brief Logger::exportLogs * \details Exports the log files from log folder (Storage::Log_Base_Path_Name_Location) * into USB drive folder (Storage::USB_Mount_Point) Index: sources/storage/Logger.h =================================================================== diff -u -raccc25a2cefe436401ad04c57713cfa410621317 -re6ddf6840cdd5a09deaac1dcdcd7d70064dc6a09 --- sources/storage/Logger.h (.../Logger.h) (revision accc25a2cefe436401ad04c57713cfa410621317) +++ sources/storage/Logger.h (.../Logger.h) (revision e6ddf6840cdd5a09deaac1dcdcd7d70064dc6a09) @@ -18,6 +18,7 @@ #include #include #include +#include // Project #include "main.h" // Doxygen : do not remove @@ -121,12 +122,14 @@ const char *_headerA = "TimeStamp,ID,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"; const char *_headerD = "TimeStamp,Description"; - const quint16 _cachetimeout = 5 ; // 5 seconds timeout until flushes, for slow traffics - quint16 _cacheCounter = _cachetimeout ; // 5 seconds timeout counter - quint16 _cacheCount = 2000; // 2K message count - CacheIndex _cacheIndex = eCache1; + const quint16 _cachetimeout = 5 ; // seconds timeout until flushes, for slow traffics + quint16 _cacheCounter = _cachetimeout ; // seconds timeout counter + quint16 _cacheCount = 3000 ; // K message count + QAtomicInt _cacheIndex = eCache1; QStringList _cacheA[eCacheIndexCount]; QStringList _cacheD[eCacheIndexCount]; + QElapsedTimer _flushElapsedA; + QElapsedTimer _flushElapsedD; QDir _dir; @@ -206,7 +209,8 @@ LogType _exportLogsType = eLogNone; QFutureWatcher _exportLogsWatcher; QFutureWatcher _removeLogsWatcher; - QFutureWatcher _flushLogsWatcher; + QFutureWatcher _flushLogsWatcherA; + QFutureWatcher _flushLogsWatcherD; QThread *_thread = nullptr; bool _init = false; @@ -327,7 +331,8 @@ * \details notification of the floush log * \param vInProgress */ - void didFlushLogs(bool vInProgress); + void didFlushLogsA(bool vInProgress); + void didFlushLogsD(bool vInProgress); // ----- Available space is low private slots: @@ -339,11 +344,13 @@ // ----- logging structure private slots: void onLog (const QString &vContent, LogType vLogType, bool vTimestamp); - bool concurrentFlushLog ( LogType vLogType); - void onFlushLogs(); + bool concurrentFlushLogA(); + bool concurrentFlushLogD(); + void onFlushLogsA(); + void onFlushLogsD(); private: bool logOverflow (LogType vLogType); - CacheIndex logSwitch (); + int logSwitch (); void logTimeout (); void log (const QString &vContent, LogType vLogType); int flush ( LogType vLogType);