-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
68 lines (61 loc) · 2.87 KB
/
main.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
61
62
63
64
65
66
67
68
#include <QCoreApplication>
#include "baselistener.h"
#include <QDebug>
#include <QtGlobal>
void noDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QByteArray localMsg = msg.toLocal8Bit();
QString current_time=QDateTime::currentDateTime().toString("ddMMyyyy-hh:mm:ss");
switch (type) {
case QtDebugMsg:
// fprintf(stderr, "Debug: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtInfoMsg:
// fprintf(stderr, "Info: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
fprintf(stderr,"%s Info: %s \n",current_time.toStdString().c_str(),localMsg.constData());
break;
case QtWarningMsg:
// fprintf(stderr, "Warning: %s (%s:%u, %s)\n", localMsg.constData(), context.file, context.line, context.function);
break;
case QtCriticalMsg:
fprintf(stderr, "%s Critical: %s (%s:%u, %s)\n",current_time.toStdString().c_str(), localMsg.constData(), context.file, context.line, context.function);
break;
case QtFatalMsg:
fprintf(stderr, "%s Fatal: %s (%s:%u, %s)\n",current_time.toStdString().c_str(), localMsg.constData(), context.file, context.line, context.function);
abort();
}
}
void DebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
QByteArray localMsg = msg.toLocal8Bit();
QString current_time=QDateTime::currentDateTime().toString("ddMMyyyy-hh:mm:ss");
switch (type) {
case QtDebugMsg:
fprintf(stderr, "%s Debug: %s (%s:%u, %s)\n",current_time.toStdString().c_str(),localMsg.constData(), context.file, context.line, context.function);
break;
case QtInfoMsg:
fprintf(stderr, "%s Info: %s (%s:%u, %s)\n",current_time.toStdString().c_str(),localMsg.constData(), context.file, context.line, context.function);
break;
case QtWarningMsg:
fprintf(stderr, "%s Warning: %s (%s:%u, %s)\n",current_time.toStdString().c_str(),localMsg.constData(), context.file, context.line, context.function);
break;
case QtCriticalMsg:
fprintf(stderr, "%s Critical: %s (%s:%u, %s)\n",current_time.toStdString().c_str(), localMsg.constData(), context.file, context.line, context.function);
break;
case QtFatalMsg:
fprintf(stderr, "%s Fatal: %s (%s:%u, %s)\n",current_time.toStdString().c_str(), localMsg.constData(), context.file, context.line, context.function);
abort();
}
}
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
if ( ! app.arguments().contains(QLatin1String("--with-debug"))) {
qInstallMessageHandler(noDebugOutput);
}
else
qInstallMessageHandler(DebugOutput);
BaseListener Server;
Server.StartServer();
return app.exec();
}