Index: sources/storage/Logger.cpp =================================================================== diff -u -re6ddf6840cdd5a09deaac1dcdcd7d70064dc6a09 -r630c0a7fe305de7fc1911df4022036c4b10e473e --- sources/storage/Logger.cpp (.../Logger.cpp) (revision e6ddf6840cdd5a09deaac1dcdcd7d70064dc6a09) +++ sources/storage/Logger.cpp (.../Logger.cpp) (revision 630c0a7fe305de7fc1911df4022036c4b10e473e) @@ -159,6 +159,8 @@ this , SLOT(onFlushLogsA())); connect(&_flushLogsWatcherD, SIGNAL(finished ()), this , SLOT(onFlushLogsD())); + connect(&_flushLogsWatcherT, SIGNAL(finished ()), + this , SLOT(onFlushLogsT())); connect(&_DeviceController, SIGNAL( didSDCardStateChange(bool, bool)), this , SLOT( onSDCardStateChange(bool, bool))); @@ -320,26 +322,26 @@ void Logger::logTimeout() { if( _cacheCounter ) { - _cacheCounter --; + _cacheCounter -- ; } else { - _cacheIndex = logSwitch(); // switch the index for caching while the flush is working - concurrentFlushLogA(); - concurrentFlushLogD(); - _cacheCounter = _cachetimeout; + _cacheIndexA = logSwitch(_cacheIndexA); // switch the index for caching while the flush is working + _cacheIndexD = logSwitch(_cacheIndexD); // switch the index for caching while the flush is working + concurrentFlushLogT(); + _cacheCounter = _cacheTimeout; } } bool Logger::logOverflow(LogType vLogType) { switch ( vLogType ) { - case eLogAppED : return _cacheA[_cacheIndex].count() >= _cacheCount; - case eLogDebug : return _cacheD[_cacheIndex].count() >= _cacheCount; - default : return _cacheD[_cacheIndex].count() >= _cacheCount; + case eLogAppED : return _cacheA[_cacheIndexA].count() >= _cacheCount; + case eLogDebug : return _cacheD[_cacheIndexD].count() >= _cacheCount; + default : return _cacheD[_cacheIndexD].count() >= _cacheCount; } } -int Logger::logSwitch() { - return _cacheIndex == eCache1 ? eCache2 : eCache1;; +int Logger::logSwitch(int vCacheIndex) { + return vCacheIndex == eCache1 ? eCache2 : eCache1;; } /*! @@ -366,18 +368,17 @@ // Add the recieved message switch ( vLogType ) { - 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; break; + case eLogAppED : _cacheA[_cacheIndexA] += mContent; break; + case eLogDebug : _cacheD[_cacheIndexD] += mContent; break; + default : _cacheD[_cacheIndexD] += QString("Incorrect type of logging %1").arg(vLogType); + _cacheD[_cacheIndexD] += mContent; break; } if ( logOverflow(vLogType) ) { - _cacheIndex = logSwitch(); // switch the index for caching while the flush is working switch ( vLogType ) { - case eLogAppED : concurrentFlushLogA(); break; - case eLogDebug : concurrentFlushLogD(); break; - default : concurrentFlushLogD(); break; + case eLogAppED : _cacheIndexA = logSwitch(_cacheIndexA); concurrentFlushLogA(); break; + case eLogDebug : _cacheIndexD = logSwitch(_cacheIndexD); concurrentFlushLogD(); break; + default : _cacheIndexD = logSwitch(_cacheIndexD); concurrentFlushLogD(); break; } } @@ -402,7 +403,6 @@ //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 - QAtomicInt cacheIndex = logSwitch(); QString mContent; QDateTime datetime = QDateTime::currentDateTime(); int count = 0; @@ -423,9 +423,9 @@ // - Add content switch ( vLogType ) { - case eLogAppED : count = _cacheA[cacheIndex].count(); mContent += _cacheA[cacheIndex].join(_sepLines); _cacheA[cacheIndex].clear(); break; - case eLogDebug : count = _cacheD[cacheIndex].count(); mContent += _cacheD[cacheIndex].join(_sepLines); _cacheD[cacheIndex].clear(); break; - default : break; //TODO create another cacheType enum + case eLogAppED : { QAtomicInt cacheIndex = logSwitch(_cacheIndexA); count = _cacheA[cacheIndex].count(); mContent += _cacheA[cacheIndex].join(_sepLines); _cacheA[cacheIndex].clear(); } break; + case eLogDebug : { QAtomicInt cacheIndex = logSwitch(_cacheIndexD); count = _cacheD[cacheIndex].count(); mContent += _cacheD[cacheIndex].join(_sepLines); _cacheD[cacheIndex].clear(); } break; + default : { } break; //TODO create another cacheType enum } // - Make log file name @@ -498,6 +498,13 @@ return count; } +int Logger::flushTimeout() { + int count = 0; + count += flush(LogType::eLogAppED); + count += flush(LogType::eLogDebug); + return count; +} + /*! * \brief Logger::concurrentFlushLogs * \details Flushes the log buffer to the file in a separate thread @@ -506,9 +513,10 @@ */ bool Logger::concurrentFlushLogA() { + qDebug() << " - " << LogType::eLogAppED << " - " << _cacheIndexA; emit didFlushLogsA(true); _flushElapsedA.start(); - LOG_DEBUG("Flush app Logs Starting"); + log("Flush app Logs Starting",LogType::eLogDebug); QFuture mFuture = QtConcurrent::run(this, &Logger::flush, LogType::eLogAppED); _flushLogsWatcherA.setFuture(mFuture); return true; @@ -522,21 +530,33 @@ */ bool Logger::concurrentFlushLogD() { + qDebug() << " - " << LogType::eLogDebug << " - " << _cacheIndexD; emit didFlushLogsD(true); _flushElapsedD.start(); - LOG_DEBUG("Flush err Logs Starting"); + log("Flush err Logs Starting",LogType::eLogDebug); QFuture mFuture = QtConcurrent::run(this, &Logger::flush, LogType::eLogDebug); _flushLogsWatcherD.setFuture(mFuture); return true; } +bool Logger::concurrentFlushLogT() +{ + qDebug() << " - " << "Timeout" << " - " << _cacheIndexA << " - " << _cacheIndexD;; + emit didFlushLogsT(true); + _flushElapsedT.start(); + log("Flush Logs Timeout Starting",LogType::eLogDebug); + QFuture mFuture = QtConcurrent::run(this, &Logger::flushTimeout); + _flushLogsWatcherT.setFuture(mFuture); + return true; +} + /*! * \brief Logger::onRemoveLogs * \details Remove old logs notification slot which logs result of remove. */ void Logger::onFlushLogsA() { - LOG_DEBUG(tr("Flush app Logs Ended: %1,%2").arg(_flushLogsWatcherA.result()).arg(_flushElapsedA.elapsed())); + log(tr("Flush app Logs Ended: %1,%2").arg(_flushLogsWatcherA.result()).arg(_flushElapsedA.elapsed()),LogType::eLogDebug); emit didFlushLogsA(false); } @@ -546,11 +566,21 @@ */ void Logger::onFlushLogsD() { - LOG_DEBUG(tr("Flush err Logs Ended: %1,%2").arg(_flushLogsWatcherD.result()).arg(_flushElapsedD.elapsed())); + log(tr("Flush err Logs Ended: %1,%2").arg(_flushLogsWatcherD.result()).arg(_flushElapsedD.elapsed()),LogType::eLogDebug); emit didFlushLogsD(false); } /*! + * \brief Logger::onRemoveLogs + * \details Remove old logs notification slot which logs result of remove. + */ +void Logger::onFlushLogsT() +{ + log(tr("Flush Logs Timeout Ended: %1,%2").arg(_flushLogsWatcherT.result()).arg(_flushElapsedT.elapsed()),LogType::eLogDebug); + emit didFlushLogsT(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)