Index: sources/storage/Logger.cpp =================================================================== diff -u -r8b044d8ef7db6f72c65aa6109d5f29a79bca92a2 -r16bd55822fa77e5bea6fdfa7b54abf123c1da8bb --- sources/storage/Logger.cpp (.../Logger.cpp) (revision 8b044d8ef7db6f72c65aa6109d5f29a79bca92a2) +++ sources/storage/Logger.cpp (.../Logger.cpp) (revision 16bd55822fa77e5bea6fdfa7b54abf123c1da8bb) @@ -86,10 +86,11 @@ void Logger::postInit() { if ( ! checkThread() ) return; - ADD_EVENT_HEADER; + ADD_APPED_HEADER; + ADD_DEBUG_HEADER; LOG_DEBUG(tr("%1 Initialized").arg(metaObject()->className())); LOG_DEBUG(tr("Application %1 Started").arg(qApp->applicationName())); - LOG_EVENT_UI(qApp-> applicationVersion()); + LOG_APPED_UI(qApp-> applicationVersion()); } /*! @@ -240,14 +241,11 @@ bool Logger::setLogPath() { bool ok = true; - // disabled coco begin validated: Has been tested manually, this needs user interaction to check the file system - if ( ok && ! setLogPath(LogType::eLogEvent) ) ok = false; - if ( ok && ! setLogPath(LogType::eLogDatum) ) ok = false; + if ( ok && ! setLogPath(LogType::eLogAppED) ) ok = false; if ( ok && ! setLogPath(LogType::eLogDebug) ) ok = false; if ( ok && ! setLogPath(LogType::eLogTrtmt) ) ok = false; return ok; } -// disabled coco end /*! * \brief Logger::setLogPath @@ -259,15 +257,7 @@ bool Logger::setLogPath(LogType vLogType) { bool ok = false; - switch (vLogType) { - case LogType::eLogDebug: - _logPathNames[vLogType] = _dir.path() + "/" + _logBasePathNames[vLogType]; - break; - - default: - _logPathNames[vLogType] = _dir.path() + "/" + _logBasePathNames[vLogType]; - break; - } + _logPathNames[vLogType] = _dir.path() + "/" + _logBasePathNames[vLogType]; ok = FileHandler::makeFolder(_logPathNames[vLogType]); if ( ok ) emit didLogPathSet(vLogType, _logPathNames[vLogType]); return ok; @@ -287,19 +277,26 @@ static QString date; QString mContent; + + // - Add header QString currentDate = QDate::currentDate().toString(_dateFormat); - if (date != currentDate) { - if (!date.isEmpty()) { - mContent = _headerE; - mContent += "\r\n" ; + if ( date != currentDate ) { + if ( ! date.isEmpty() ) { + switch ( vLogType ) { + case eLogAppED : mContent = _headerA; break; + case eLogDebug : mContent = _headerD; break; + // case LogType::eLogTrtmt: // this type of log will never happen here. Only put here to make sure it is intentional. + default : mContent = _headerD; break; + } + mContent += "\r\n"; } date = currentDate; } + // - Make log file name QString fileName = date + _dateSeparator + _logFileNamePrefix; switch (vLogType) { - case LogType::eLogEvent: - case LogType::eLogDatum: + case LogType::eLogAppED: case LogType::eLogDebug: // case LogType::eLogTrtmt: // this type of log will never happen here. Only put here to make sure it is intentional. fileName += _logFileNameExt[vLogType]; @@ -310,28 +307,26 @@ LOG_DEBUG(QString("Incorrect type of logging %1").arg(vLogType)); } + // - Add timestamp if ( vTimestamp ) mContent = QTime::currentTime().toString(_timeFormat) + _separator; - QString logPrefix = _logPrefix[vLogType]; - if (vTimestamp && ! logPrefix.isEmpty()) { - mContent += logPrefix; - mContent += _separator; - } + // - Add the content mContent += vContent; // some messages like the version having the U08(uchar) parameters which converts to '\0' and causes problems in reading the log file. mContent.replace('\0', "0"); + // - Make the log path and write to log. QString logPathName = _logPathNames[vLogType]; if (logPathName.isEmpty()) logPathName = _logPathNames[eLogDebug]; _logFileName = logPathName + fileName; FileHandler::write(_logFileName, mContent + "\r\n", true); - // disabled coco begin validated: This code is only for debugging purposes and had been tested manually. + + // console out the log if enabled. if (_enableConsoleOut) { qDebug().noquote() << mContent; } - // disabled coco end } /*! @@ -342,21 +337,14 @@ */ bool Logger::exportLogs(const Gui::GuiStringIndexMap &vExportList) { - // DEBUG: qDebug() << __FUNCTION__ << vExportList; return false; + // DEBUG: + qDebug() << __FUNCTION__ << vExportList; return false; // qDebug() << " ~~~~~~~~~~ " << QThread::currentThread()->objectName(); int result = 0; - static QString mOSource; QString mDestination = USB_Mount_Point; - for ( const auto &iType : { eLogEvent, eLogDatum } ) { - QString mCSource = _logPathNames[iType]; - // if the event and datum are mixed (mOSource == mCSource) in one file then no need to go over the same files in same folder and do it again. - if (mOSource != mCSource) { - mOSource = mCSource; - // Copy Folder - result = FileHandler::copyFolder( mCSource, mDestination); - } - } - mOSource = ""; + QString mCSource = _logPathNames[eLogAppED]; + // Copy Folder + result = FileHandler::copyFolder( mCSource, mDestination); return result >= 0; // refer to QProcess::execute(hit F1 on execute) doc. } @@ -368,7 +356,8 @@ */ bool Logger::exportErrs(const Gui::GuiStringIndexMap &vExportList) { - // DEBUG: qDebug() << __FUNCTION__ << vExportList; return false; + // DEBUG: + qDebug() << __FUNCTION__ << vExportList; return false; // qDebug() << " ~~~~~~~~~~ " << QThread::currentThread()->objectName(); int result = 0; QString mDestination = USB_Mount_Point; @@ -386,7 +375,8 @@ */ bool Logger::exportTrts(const Gui::GuiStringIndexMap &vExportList) { - // DEBUG: qDebug() << __FUNCTION__ << vExportList; return false; + // DEBUG: + qDebug() << __FUNCTION__ << vExportList; return false; // qDebug() << " ~~~~~~~~~~ " << QThread::currentThread()->objectName(); int result = 0; QString mDestination = USB_Mount_Point; @@ -420,7 +410,7 @@ { if ( ! concurrentExportIsOk() ) return false; - _exportLogsType = eLogEvent; + _exportLogsType = eLogAppED; LOG_DEBUG(QString("Export %1 start").arg(_logNames[_exportLogsType])); QFuture future = QtConcurrent::run(this, &Logger::exportLogs, vExportList); _exportLogsWatcher.setFuture(future); @@ -481,64 +471,45 @@ */ int Logger::removeLogs() { - // disabled coco begin validated: This needs user interaction to check the old files deleted // Storage::FileHandler::find("/media/denali/0CAA-40C1/log/", {"*.err"}, 15); return 0; // has been tested manually LOG_DEBUG(tr("Initializing log clean up")); - static QString mOSource; - static QString mOExtension; int removeCount = 0; - QString mLogFileFilter; - for ( const auto &iType : { eLogEvent , eLogDatum , eLogDebug , eLogTrtmt } ) { + for ( const auto &iType : { eLogAppED , eLogDebug , eLogTrtmt } ) { QString mCSource = _logPathNames [iType]; QString mCExtension = _logFileNameExt[iType]; - // if the event and datum are mixed (mOSource == mCSource && mCExtension == mOExtension) in one file then no need to go over the same files in same folder and do it again. - if (mOSource != mCSource || mCExtension != mOExtension) { - mOSource = mCSource; - mOExtension = mCExtension; - // Remove Logs - // TODO: It appeared to me that the filter on extension may not be necessary, since the folder of each type is different. - // NOTE: The filter on the extension comes from the idea that in the same folder(log) we may want to separate the event(log) from datum(dat) with different usage percentage. -#ifdef MIXED_EVENT_DATUM - mLogFileFilter = QString("*%1").arg(".*"); -#else - mLogFileFilter = QString("*%1").arg(mCExtension); -#endif - // DEBUG: qDebug() << "@" << mCSource << mLogFileFilter << mCExtension << iType << _logTypeMaxUsageLimit[iType]; - QFileInfoList fileInfoList = FileHandler::find(mCSource, {mLogFileFilter}, _logTypeMaxUsageLimit[iType]); - removeCount = fileInfoList.count(); - // qDebug() << "@" << removeCount << fileInfoList; - if (removeCount) { - LOG_DEBUG(QString("Removing %1 logs of type (%2) more than %3% limit from folder %4") - .arg(removeCount) - .arg(mCExtension) - .arg(_logTypeMaxUsageLimit[iType]) - .arg(mCSource)); - for (const auto &info: fileInfoList) { - if (info.lastModified().date() == QDate().currentDate()) { - LOG_DEBUG(QString("Current day log %1 cannot be deleted").arg(info.fileName())); + // DEBUG: qDebug() << "@" << mCSource << mLogFileFilter << mCExtension << iType << _logTypeMaxUsageLimit[iType]; + QFileInfoList fileInfoList = FileHandler::find(mCSource, {"*.*"}, _logTypeMaxUsageLimit[iType]); + removeCount = fileInfoList.count(); + // qDebug() << "@" << removeCount << fileInfoList; + if (removeCount) { + LOG_DEBUG(QString("Removing %1 logs of type (%2) more than %3% limit from folder %4") + .arg(removeCount) + .arg(mCExtension) + .arg(_logTypeMaxUsageLimit[iType]) + .arg(mCSource)); + for (const auto &info: fileInfoList) { + if (info.lastModified().date() == QDate().currentDate()) { + LOG_DEBUG(QString("Current day log %1 cannot be deleted").arg(info.fileName())); + } + else { + QString mFileName = mCSource + info.fileName(); + // DEBUG: qDebug() << "#" << mFileName; + bool ok = QFile::remove(mFileName); + if (ok) { + LOG_DEBUG(QString("Removing %1 succeeded").arg(mFileName)); + } else { + LOG_DEBUG(QString("Removing %1 failed" ).arg(mFileName)); } - else { - QString mFileName = mCSource + info.fileName(); - // DEBUG: qDebug() << "#" << mFileName; - bool ok = QFile::remove(mFileName); - if (ok) { - LOG_DEBUG(QString("Removing %1 succeeded").arg(mFileName)); - } else { - LOG_DEBUG(QString("Removing %1 failed" ).arg(mFileName)); - } - } } } - else { - LOG_DEBUG("No log file is deleted for " + mCExtension); - } } + else { + LOG_DEBUG("No log file is deleted for " + mCExtension); + } } - mOSource = ""; return removeCount; } -// disabled coco end /*! * \brief Logger::concurrentRemoveLogs