Repository navigation
Expand file tree
/
Copy pathapplog.cpp
More file actions
100 lines (83 loc) · 1.96 KB
/
Copy pathapplog.cpp
File metadata and controls
100 lines (83 loc) · 1.96 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#if _MSC_VER >= 1600
#pragma execution_character_set("utf-8")
#endif
#include "applog.h"
#include "myhelper.h"
//输出所有打印调试信息到日志文件
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
void Log(QtMsgType type, const char *msg)
{
QString content;
switch (type) {
case QtDebugMsg:
content = QString("%1").arg(msg);
break;
case QtWarningMsg:
content = QString("%1").arg(msg);
break;
case QtCriticalMsg:
content = QString("%1").arg(msg);
break;
case QtFatalMsg:
content = QString("%1").arg(msg);
exit(0);
}
if (content.startsWith("libpng")) {
return;
}
QString logFile = QString("%1/log/%2_Log_%3.txt").arg(App::AppPath).arg(App::AppName).arg(QDATE);
QFile log(logFile);
log.open(QIODevice::WriteOnly | QIODevice::Append | QFile::Text);
QTextStream logStream(&log);
logStream << content << "\n";
}
#else
void Log(QtMsgType type, const QMessageLogContext &, const QString &msg)
{
QString content;
switch (type) {
case QtDebugMsg:
content = QString("%1").arg(msg);
break;
case QtWarningMsg:
content = QString("%1").arg(msg);
break;
case QtCriticalMsg:
content = QString("%1").arg(msg);
break;
case QtFatalMsg:
content = QString("%1").arg(msg);
exit(0);
}
if (content.startsWith("libpng")) {
return;
}
QString logFile = QString("%1/log/%2_Log_%3.txt").arg(App::AppPath).arg(App::AppName).arg(QDATE);
QFile log(logFile);
log.open(QIODevice::WriteOnly | QIODevice::Append | QFile::Text);
QTextStream logStream(&log);
logStream << content << "\n";
}
#endif
AppLog *AppLog::_instance = 0;
AppLog::AppLog(QObject *parent) : QObject(parent)
{
}
//安装日志钩子,输出调试信息到文件,便于调试
void AppLog::Start()
{
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
qInstallMsgHandler(Log);
#else
qInstallMessageHandler(Log);
#endif
}
//卸载日志钩子
void AppLog::Stop()
{
#if (QT_VERSION <= QT_VERSION_CHECK(5,0,0))
qInstallMsgHandler(0);
#else
qInstallMessageHandler(0);
#endif
}