Index: sources/storage/logger.cpp =================================================================== diff -u -r3aab84456cfbdc4c4f495975ba9b8968eb844309 -r920342d3f8cb8c29966f2354ebc7d241df23ccf7 --- sources/storage/logger.cpp (.../logger.cpp) (revision 3aab84456cfbdc4c4f495975ba9b8968eb844309) +++ sources/storage/logger.cpp (.../logger.cpp) (revision 920342d3f8cb8c29966f2354ebc7d241df23ccf7) @@ -99,18 +99,18 @@ */ void Logger::initConnections() { - connect(&_exportWatcher, SIGNAL(finished()), - this , SLOT(onExport())); + connect(&_exportLogsWatcher, SIGNAL(finished ()), + this , SLOT(onExportLogs())); connect(this, SIGNAL(didLog(QString,LogType)), this, SLOT( onLog(QString,LogType))); - connect(&_MainTimer, SIGNAL( didDateChange ()), - this , SLOT( concurrentRemoveOldLogs())); + connect(&_MainTimer, SIGNAL( didDateChange ()), + this , SLOT( concurrentRemoveLogs())); - connect(&_removeOldLogsWatcher, SIGNAL(finished ()), - this , SLOT(onRemoveOldLogs())); + connect(&_removeLogsWatcher, SIGNAL(finished ()), + this , SLOT(onRemoveLogs())); connect(&_DriveWatcher, SIGNAL( didSDCardSpaceChange(bool, qint64, qint64, quint8)), this , SLOT( onSDCardSpaceChange(bool, qint64, qint64, quint8))); @@ -276,81 +276,116 @@ } } + +bool Logger::exportLogs() +{ + int result = 0; + static QString mOSource; + QString mDestination = USB_Mount_Point; + for ( const auto &iType : { eLogEvent , eLogDatum } ) { + QString mCSource = _logPathNames[iType]; + if (mOSource != mCSource) { + mOSource = mCSource; + // Copy Folder + result = FileHandler::copyFolder( mCSource, mDestination); + } + } + mOSource = ""; + return result >= 0; // refer to QProcess::execute(hit F1 on execute) doc. +} + /*! - * \brief Logger::concurrentExport + * \brief Logger::concurrentExportLogs * \details Exports the log files from log folder (Storage::Log_Base_Path_Name_Location) * into USB drive folder (Storage::USB_Mount_Point) * \return always returns true for now. * \note This method uses QtConcurrent run to execute the FileHandler copyFolder method. */ -bool Logger::concurrentExport() +bool Logger::concurrentExportLogs() { // coco begin validated: This needs user interaction to export to USB device // has been tested manually - QString mSource = SDCard_Base_Path_Name; - QString mDestination = USB_Mount_Point; - QFuture future = QtConcurrent::run(&FileHandler::copyFolder, mSource, mDestination); - _exportWatcher.setFuture(future); - return true; + LOG_DEBUG("Export Logs Start"); + QFuture future = QtConcurrent::run(this, &Logger::exportLogs); + _exportLogsWatcher.setFuture(future); + return true; } // coco end -void Logger::onExport() +void Logger::onExportLogs() { // coco begin validated: This needs user interaction to export to USB device // has been tested manually - emit didExport(); + LOG_DEBUG(QString("Export Logs Ended: %1").arg(_exportLogsWatcher.result())); + emit didExportLogs(); } // coco end /*! - * \brief Logger::removeOldLogs + * \brief Logger::removeLogs * \details Remove old logs by iterating in the log/service folders and look for expired logs. * \return count file(s) have been removed. */ -int Logger::removeOldLogs() +int Logger::removeLogs() { // coco begin validated: This needs user interaction to check the old files deleted // has been tested manually - QStringList mLogFileFilter ; - QDate mOlderThan ; - for (int iType = 0; iType < eLogType_Count; iType++) { - LogType logType = static_cast(iType); - mLogFileFilter = Format::toStringList(_logFileNameExt .values(logType), true, "*"); - mOlderThan = QDate().currentDate().addDays( _logTypeExpiryDay.value(logType) * -1 ); - FileHandler::removeFiles({_logPathNames[logType]}, mLogFileFilter, mOlderThan); + static QString mOSource; + int countRemoved = 0; + QStringList mLogFileFilter; + QDate mOlderThan ; + for ( const auto &iType : { eLogEvent , eLogDatum , eLogDebug } ) { + QString mCSource = _logPathNames[iType]; + if (mOSource != mCSource) { + mOSource = mCSource; + // Remove Logs + if (_logTypeExpiryDay.value(iType)) { + mOlderThan = QDate().currentDate().addDays( _logTypeExpiryDay.value(iType) * -1 /*Please Notice (-1)*/ ); + mLogFileFilter = Format::toStringList(_logFileNameExt .values(iType), true, "*"); + LOG_DEBUG(QString("Removing logs older than %1 from folder %2").arg(mOlderThan.toString("yyyy-MM-dd")).arg(mCSource)); + countRemoved += FileHandler::removeFiles({ mCSource }, mLogFileFilter, mOlderThan); + } + else { + LOG_DEBUG("Current day logs cannot be deletet"); + } + } } - - return true; + mOSource = ""; + return countRemoved; } // coco end /*! - * \brief Logger::concurrentRemoveOldLogs + * \brief Logger::concurrentRemoveLogs * \details * * \return always returns true for now. * \note This method uses QtConcurrent run to execute the FileHandler copyFolder method. */ -bool Logger::concurrentRemoveOldLogs() +bool Logger::concurrentRemoveLogs() { // coco begin validated: This needs user interaction to check the old files deleted // has been tested manually - QFuture mFuture = QtConcurrent::run(this,&Logger::removeOldLogs); - _removeOldLogsWatcher.setFuture(mFuture); - return true; + LOG_DEBUG("Remove Logs Start"); + QFuture mFuture = QtConcurrent::run(this,&Logger::removeLogs); + _removeLogsWatcher.setFuture(mFuture); + return true; } // coco end -void Logger::onRemoveOldLogs() +void Logger::onRemoveLogs() { // coco begin validated: This needs user interaction to export to USB device // has been tested manually - emit didRemoveOldLogs(); + LOG_DEBUG(QString("Remove Logs Ended: %1").arg(_removeLogsWatcher.result())); + emit didRemoveLogs(); } void Logger::onSDCardSpaceChange(bool vReady, qint64 vTotal, qint64 vAvailable, quint8 vPercent) { + if (vPercent > 10 ) { + concurrentRemoveLogs(); + } qDebug() << vReady << vTotal << vAvailable << vPercent; } // coco end