#include "nmDataLogFile.h" #include #include #include nmDataLogFile::nmDataLogFile(QObject *parent) : QObject(parent) { m_logFile = new QFile("nmDebug.log"); if (m_logFile->open(QIODevice::WriteOnly | QIODevice::Append)) { m_textStream = new QTextStream(m_logFile); m_textStream->setCodec("UTF-8"); } } nmDataLogFile::~nmDataLogFile() { if (m_logFile != NULL) { m_logFile->close(); delete m_logFile; delete m_textStream; } } nmDataLogFile* nmDataLogFile::s_instance = NULL; nmDataLogFile* nmDataLogFile::getInstance() { if (NULL == s_instance) { s_instance = new nmDataLogFile(); } return s_instance; } void nmDataLogFile::writeLog(const QString &message) { *m_textStream << QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss") << " - " << message << endl; m_logFile->flush(); }