You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
915 B
C++
39 lines
915 B
C++
#include "nmDataLogFile.h"
|
|
#include <QFile>
|
|
#include <QDateTime>
|
|
#include <QTextStream>
|
|
|
|
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();
|
|
}
|