Index: sources/storage/logger.cpp =================================================================== diff -u -r805119c460b4a266d6401c8705f4427e7fbe270f -r44a85c96ab55e424866ec4cca0270aa218355f82 --- sources/storage/logger.cpp (.../logger.cpp) (revision 805119c460b4a266d6401c8705f4427e7fbe270f) +++ sources/storage/logger.cpp (.../logger.cpp) (revision 44a85c96ab55e424866ec4cca0270aa218355f82) @@ -1,15 +1,16 @@ /*! - * + * * Copyright (c) 2019-2020 Diality Inc. - All Rights Reserved. - * \copyright \n - * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, \n - * IN PART OR IN WHOLE, \n - * WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. \n - * - * \file logger.cpp - * \date 2019/09/30 - * \author Behrouz NematiPour - * + * \copyright + * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN + * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. + * + * \file logger.cpp + * \author (last) Behrouz NematiPour + * \date (last) 13-Apr-2020 + * \author (original) Behrouz NematiPour + * \date (original) 24-Sep-2019 + * */ #include "logger.h" @@ -65,10 +66,13 @@ */ bool Logger::init(QThread &vThread) { + // coco begin validated: Application is not running in multi-threaded mode for testing + // it has been tested and works perfectly fine in normal run. if ( ! init() ) return false; initThread(vThread); return true; } +// coco end /*! * \brief Logger quit @@ -79,7 +83,7 @@ { // coco begin validated: Application termination is not correctly done in coco!!! // it has been tested and works perfectly fine in normal run. - quitThread(); + quitThread(); // validated } // coco end @@ -112,6 +116,8 @@ */ void Logger::initThread(QThread &vThread) { + // coco begin validated: Application is not running in multi-threaded mode for testing + // it has been tested and works perfectly fine in normal run. // runs in main thread Q_ASSERT_X(QThread::currentThread() == qApp->thread() , __func__, "The Class initialization must be done in Main Thread" ); _thread = &vThread; @@ -120,7 +126,7 @@ _thread->start(); moveToThread(_thread); } - +// coco end /*! * \brief Logger::quitThread * \details Moves this object to main thread to be handled by QApplicaiton @@ -130,11 +136,10 @@ { // coco begin validated: Application termination is not correctly done in coco!!! // it has been tested and works perfectly fine in normal run. - if (! _thread) return; // runs in thread - moveToThread(qApp->thread()); + moveToThread(qApp->thread()); // validated } // coco end @@ -145,7 +150,10 @@ void Logger::checkLogPath() { setLogBasePath(); // try to use /media/sd_card on device + // coco begin validated: It can only happen if the file system is readonly for any reson. + // it has been tested and works perfectly fine in normal run. if (! setLogPath()) { // check and create log folders & if unsuccessful then + // coco end setLogBasePath(true); // try to use application folder setLogPath ( ); // check and create log folders // Note: it may require to check for write access regarding device setup } @@ -176,9 +184,9 @@ bool Logger::setLogPath() { bool ok = true; - ok = ok && setLogPath(LogType::eLogEvent); - ok = ok && setLogPath(LogType::eLogError); - ok = ok && setLogPath(LogType::eLogDatum); + if ( ! setLogPath(LogType::eLogEvent) ) ok = false; + if ( ! setLogPath(LogType::eLogError) ) ok = false; + if ( ! setLogPath(LogType::eLogDatum) ) ok = false; return ok; } @@ -222,16 +230,22 @@ case eLogError: case eLogDatum: break; + default: LOG_ERROR(tr("Incorrect type of logging").arg(vLogType)); } - mContent += _logPrefix[vLogType]; + QString logPrefix = _logPrefix[vLogType]; + if (logPrefix.isEmpty()) logPrefix = _logPrefix[LogType::eLogError]; + mContent += logPrefix; mContent += _prefixSeparator; mContent += QTime::currentTime().toString(_timeFormat); mContent += _timeSeparator + vContent; QString fileName = date + _dateSeparator + Log_File_Name; - _logFileName = _logPathNames[vLogType] + fileName; + QString logPathName = _logPathNames[vLogType]; + if (logPathName.isEmpty()) + logPathName = _logPathNames[LogType::eLogError]; + _logFileName = logPathName + fileName; FileHandler::write(_logFileName, mContent + "\r\n", true); if (vLogType == eLogError) { #ifdef QT_DEBUG @@ -257,7 +271,6 @@ QString mDestination = Storage::USB_Mount_Point; QFuture future = QtConcurrent::run(&FileHandler::copyFolder, mSource, mDestination); _exportWatcher.setFuture(future); - future.waitForFinished(); return true; } // coco end