forked from powersst/Maple-Tree
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdebug.cpp
60 lines (56 loc) · 1.54 KB
/
debug.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
50
51
52
53
54
55
56
57
58
59
60
#include "debug.h"
#include "mapleseed.h"
bool Debug::isEnabled = false;
Debug::Debug(QObject *parent) : QObject(parent)
{
}
void Debug::categoryFilter(QLoggingCategory *category)
{
if (strcmp(category->categoryName(), "default") == 0)
{
category->setEnabled(QtDebugMsg, isEnabled);
}
else if (strcmp(category->categoryName(), "qt.gamepad") == 0)
{
category->setEnabled(QtDebugMsg, isEnabled);
}
else
{
category->setEnabled(QtDebugMsg, false);
}
}
void Debug::messageOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QByteArray localMsg = msg.toLocal8Bit();
const char *file = context.file ? context.file : "";
const char *function = context.function ? context.function : "";
QString qtype;
switch (type)
{
case QtDebugMsg:
qtype = "Debug";
break;
case QtInfoMsg:
qtype = "Info";
break;
case QtWarningMsg:
qtype = "Warning";
break;
case QtCriticalMsg:
qtype = "Critical";
break;
case QtFatalMsg:
qtype = "Fatal";
break;
}
#ifdef QT_DEBUG
MapleSeed::self->messageLog(QString("%1: %2 (%3:%4, %5)")
.arg(qtype)
.arg(localMsg.constData())
.arg(file)
.arg(context.line)
.arg(function));
#else
MapleSeed::self->messageLog(QString("%1: %2").arg(qtype).arg(localMsg.constData()));
#endif
}