-
Notifications
You must be signed in to change notification settings - Fork 0
/
debug_log.cpp
49 lines (39 loc) · 1.21 KB
/
debug_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
46
47
48
49
#include "debug_log.h"
#include "blockchain.h"
void outputMessage(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
static QMutex mutex;
mutex.lock();
QString text;
switch (type)
{
case QtDebugMsg:
text = QString("Debug:");
break;
case QtWarningMsg:
text = QString("Warning:");
break;
case QtCriticalMsg:
text = QString("Critical:");
break;
case QtFatalMsg:
text = QString("Fatal:");
}
//QString context_info = QString("File:(%1) Line:(%2) FUN:(%3)").arg(QString(context.file)).arg(context.line).arg(context.function);
QString current_date_time = QDateTime::currentDateTime().toString("yyyy-MM-dd hh:mm:ss ddd");
QString current_date = QString("(%1)").arg(current_date_time);
QString message = QString("%1 %2 %3").arg(text).arg(current_date).arg(msg);
QFile file( Blockchain::getInstance()->walletConfigPath + "/log.txt");
if(file.open(QIODevice::WriteOnly | QIODevice::Append))
{
if( file.size() > 1000000)
{
file.resize(0);
}
QTextStream text_stream(&file);
text_stream << message << "\r\n";
file.flush();
file.close();
}
mutex.unlock();
}