-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.h
126 lines (106 loc) · 2.35 KB
/
logger.h
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
#ifndef LOGGER_H
#define LOGGER_H
#include "jconfig.h"
#define LOG_DEF_FILENAME QApplication::applicationDirPath() + "/terminal.log"
#define Log Logger::instance()
/*
"targets":
{
"stderr":
{
"target" : "err"
},
"syslog":
{
"target" : "syslog",
"facility" : "daemon"
},
"write to file":
{
"target" : "file",
"path" : "terminal.log"
},
"console":
{
"target" : "pipe",
"path" : "/dev/xconsole"
}
},
"routes":
[
{
"source" : "ipc",
"level" : "warn",
"target" : "write to file"
},
{
"source" : "*" ,
"level" : ["debug", "notice"],
"target" : null
},
{
"source" : "default",
"level" : "*",
"target" : ["stderr", "syslog"]
}
]
===
source level target
target
target
…
level target
…
…
source …
…
*/
class LogTarget;
class Logger
{
public:
enum Level
{
LevelNone,
LevelDebug,
LevelInfo,
LevelWarn,
LevelErr,
LevelCrit,
LevelFatal,
LevelAll,
LevelDefault
};
struct LogMessage
{
QString source;
QString msg;
};
~Logger();
void addRoute(const Json &source, const Json &level, const Json &target);
void addRoute(const QString &source, const Json &level, const Json &target);
void addRoute(const QString &source, enum Level level, const Json &target);
void addRoute(const QString &source, enum Level level, const QString &target);
void debug(const QString &source, const QString &msg);
void info(const QString &source, const QString &msg);
void warning(const QString &source, const QString &msg);
void error(const QString &source, const QString &msg);
void critical(const QString &source, const QString &msg);
void fatal(const QString &source, const QString &msg);
void log(const QString &source, enum Level level, const QString &msg);
static Logger *instance(const JConfig &conf = JConfig());
static void clear();
static enum Level stringToLevel(const QString &level);
protected:
Logger();
Logger(const JConfig &conf);
private:
typedef QMap<Level,LogTarget *> LogRoutes;
typedef QMap<QString,LogRoutes> LogRouteMap;
typedef QMap<QString,LogTarget *> LogTargetMap;
LogRouteMap m_routes;
LogTargetMap m_targets;
static Logger *m_instance;
void send(LogRoutes &routes, const QString &source, enum Level level, const QString &msg);
};
#endif // LOGGER_H