27 lines
566 B
C++
27 lines
566 B
C++
|
#include "HxLog.h"
|
||
|
|
||
|
#include <QFile>
|
||
|
#include <QDateTime>
|
||
|
|
||
|
QMutex HxLog::mutex;
|
||
|
|
||
|
void HxLog::append(QString title, QString message)
|
||
|
{
|
||
|
mutex.lock();
|
||
|
|
||
|
auto current_time = QDateTime::currentDateTime();
|
||
|
|
||
|
QFile file(QString("log/%1.log").arg(current_time.toString("yyyyMMdd")));
|
||
|
|
||
|
if (file.open(QIODevice::WriteOnly | QIODevice::Append))
|
||
|
{
|
||
|
auto data = QString("[%1] | [%2] | %3\r\n").arg(current_time.toString("yyyy-MM-dd HH:mm:ss"), title, message);
|
||
|
|
||
|
file.write(data.toLocal8Bit());
|
||
|
|
||
|
file.close();
|
||
|
}
|
||
|
|
||
|
mutex.unlock();
|
||
|
}
|