Index: sources/storage/logger.cpp =================================================================== diff -u -rfeb3423b373dc2a2c4267ef9fcb4d924d738423d -r5e78f0799b46963feb5756decb1a27b952cd19b3 --- sources/storage/logger.cpp (.../logger.cpp) (revision feb3423b373dc2a2c4267ef9fcb4d924d738423d) +++ sources/storage/logger.cpp (.../logger.cpp) (revision 5e78f0799b46963feb5756decb1a27b952cd19b3) @@ -27,22 +27,28 @@ using namespace Storage; -// Singleton -SINGLETON_INIT(Logger) - - Logger::Logger(QObject *parent) : QObject(parent) { } bool Logger::init() { + // runs in main thread + Q_ASSERT_X(QThread::currentThread() == qApp->thread() , "_Logger::init", "The Class initialization must be done in Main Thread" ); + + // runs in Logger thread checkLogPath(); qRegisterMetaType("LogType"); initConnections(); return true; } -void Logger::initConnections() { } +void Logger::quit() +{ +} +void Logger::initConnections() +{ +} + void Logger::checkLogPath() { setLogBasePath(); // try to use /media/sd_card on device @@ -56,7 +62,7 @@ { if (vUseApplicationDirPath) { _dir.setPath(qApp->applicationDirPath()); - qDebug() << "WARNING :" << tr("Application Dir Path used for events logging (%1)").arg(_dir.path()); + LOG_EVENT(tr("Application Dir Path used for events logging (%1)").arg(_dir.path())); } else { _dir.setPath(Log_Base_Path_Name); } @@ -76,18 +82,19 @@ _logPathNames[vLogType] = _dir.path() + "/" + _logBasePathNames[vLogType]; if ( ! _dir.exists(_logBasePathNames[vLogType]) ) { if ( ! _dir.mkpath(_logBasePathNames[vLogType]) ) { - qDebug() << "ERROR :" << tr("Can't create %1 log path (%2)") - .arg(_logPrefix[vLogType]) - .arg(_logPathNames[vLogType]) - ; + LOG_ERROR(tr("Can't create %1 log path (%2)") + .arg(_logPrefix[vLogType]) + .arg(_logPathNames[vLogType]) + ); return false; } } return true; } -bool Logger::log(const QString &vContent, LogType vLogType) { - //qDebug() << QThread::currentThread()->objectName(); +void Logger::log(const QString &vContent, Logger::LogType vLogType) +{ + PRINT_THREAD_NAME; QString date = QDate::currentDate().toString(_dateFormat); QString mContent; @@ -105,18 +112,16 @@ mContent += QTime::currentTime().toString(_timeFormat); mContent += _timeSeparator + vContent; QString fileName = date + _dateSeparator + Log_File_Name; - _FileHandler->onWrite(_logPathNames[vLogType] + fileName, mContent + "\r\n"); - qDebug().noquote() << mContent; - - return true; + FileHandler::write(_logPathNames[vLogType] + fileName, mContent + "\r\n", true); + if (vLogType == eLogError) { + qDebug().noquote() << mContent; + } } -void Logger::doLog(const QString &vContent, LogType vLogType) +void Logger::concurrentLog(const QString &vContent, LogType vLogType) { - // // QMetaObject::invokeMethod(this, "log", Qt::AutoConnection, Q_ARG(QString, vContent) , Q_ARG(LogType, vLogType)); - - // /* QFuture future = */QtConcurrent::run(this,&Logger::log, vContent, vLogType); - // // qDebug() << future.result(); - - log(vContent, vLogType); + PRINT_THREAD_NAME; + // QFuture future = + QtConcurrent::run(this,&Logger::log, vContent, vLogType); + // qDebug() << future.result(); }