-
Notifications
You must be signed in to change notification settings - Fork 0
/
Log.cpp
45 lines (41 loc) · 898 Bytes
/
Log.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "Log.h"
#include <QDateTime>
#include <QFile>
#include <QMutex>
QMutex mutex;
void writeLog(QtMsgType type, const QMessageLogContext &context,
const QString &msg)
{
QString str = QDateTime::currentDateTime().
toString("dd.MM.yyyy hh:mm:ss.zzz ");
switch (type) {
case QtDebugMsg:
str += "[DEBUG ]";
break;
case QtInfoMsg:
str += "[INFO ]";
break;
case QtWarningMsg:
return;
str += "[WARNING]";
break;
case QtCriticalMsg:
str += "[ERROR ]";
break;
case QtFatalMsg:
str += "[FATAL ]";
break;
}
str += " " + msg + "\n";
QFile file("UserTRX.log");
if(!file.open(QFile::Append | QFile::Text))
{
QString error = "log file open error ";
error += file.errorString();
qFatal(error.toStdString().c_str());
}
mutex.lock();
file.write(str.toUtf8());
file.close();
mutex.unlock();
}