-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
146 lines (122 loc) · 3.42 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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/****************************************************************
* main.cpp
* by zapmaker
*
* 15 Nov 2012
* GPL License (see LICENSE file)
* Software is provided AS-IS
****************************************************************/
#include "mainwindow.h"
#include <QApplication>
enum GC_LOG_TYPES
{
LOG_DEBUG_TYPE = 1,
LOG_ERROR_TYPE,
LOG_WARN_TYPE,
LOG_INFO_TYPE,
LOG_STATUS_TYPE,
};
void logit(GC_LOG_TYPES type, const char *str, va_list args);
Log4Qt::PatternLayout *p_layout;
int main(int argc, char *argv[])
{
// setup logging
Log4Qt::LogManager::rootLogger();
//Log4Qt::TTCCLayout *p_layout = new Log4Qt::TTCCLayout(Log4Qt::TTCCLayout::ISO8601);
//Log4Qt::PatternLayout *p_layout = new Log4Qt::PatternLayout(Log4Qt::PatternLayout::TTCC_CONVERSION_PATTERN);
p_layout = new Log4Qt::PatternLayout("%d %p (%c) - %m%n");
p_layout->setName(QLatin1String("GC Basic Layout"));
p_layout->activateOptions();
// Create a console appender
Log4Qt::ConsoleAppender *p_appender = new Log4Qt::ConsoleAppender(p_layout, Log4Qt::ConsoleAppender::STDOUT_TARGET);
p_appender->setName(QLatin1String("GC Basic Console Appender"));
//#ifdef QT_DEBUG
p_appender->setThreshold(Log4Qt::Level::TRACE_INT);
//#else
// p_appender->setThreshold(Log4Qt::Level::WARN_INT);
//#endif
p_appender->activateOptions();
Log4Qt::Logger::rootLogger()->addAppender(p_appender);
QApplication a(argc, argv);
MainWindow w;
w.show();
return a.exec();
}
//------------------------------
void status(const char *str, ...)
{
va_list args;
va_start(args, str );
logit(LOG_STATUS_TYPE, str, args);
va_end(args);
}
void err(const char *str, ...)
{
va_list args;
va_start(args, str );
logit(LOG_ERROR_TYPE, str, args);
va_end(args);
}
void warn(const char *str, ...)
{
va_list args;
va_start(args, str );
logit(LOG_WARN_TYPE, str, args);
va_end(args);
}
void info(const char *str, ...)
{
va_list args;
va_start(args, str );
logit(LOG_INFO_TYPE, str, args);
va_end(args);
}
void diag(const char *str, ...)
{
va_list args;
va_start(args, str );
logit(LOG_DEBUG_TYPE, str, args);
va_end(args);
}
void logit(GC_LOG_TYPES type, const char *str, va_list args)
{
#define PRNTBUFSIZE 500
char buf[PRNTBUFSIZE];
buf[PRNTBUFSIZE-1] = '\0';
vsnprintf(buf, sizeof(buf) - 1, str, args);
int len = strlen(buf);
if (len > 0)
{
if (len == 1 && (buf[0] == '\r' || buf[0] == '\n'))
{
buf[0] = '\0';
}
else if (len > 1)
{
if (buf[len - 2] == '\r' || buf[len - 2] == '\n')
buf[len - 2] = '\0';
else if (buf[len - 1] == '\r' || buf[len - 1] == '\n')
buf[len - 1] = '\0';
}
}
else if (len == 0)
return;
switch (type)
{
case LOG_STATUS_TYPE:
Log4Qt::Logger::logger(LOG_MSG_TYPE_STATUS)->info(buf);
break;
case LOG_DEBUG_TYPE:
Log4Qt::Logger::logger(LOG_MSG_TYPE_DIAG)->debug(buf);
break;
case LOG_ERROR_TYPE:
Log4Qt::Logger::logger(LOG_MSG_TYPE_DIAG)->error(buf);
break;
case LOG_WARN_TYPE:
Log4Qt::Logger::logger(LOG_MSG_TYPE_DIAG)->warn(buf);
break;
case LOG_INFO_TYPE:
Log4Qt::Logger::logger(LOG_MSG_TYPE_DIAG)->info(buf);
break;
}
}