-
Notifications
You must be signed in to change notification settings - Fork 0
/
Logger.cpp
84 lines (79 loc) · 1.84 KB
/
Logger.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
#include "Logger.h"
static LoggerInterface *log = NULL;
int logger_init(const int type)
{
int ret = -1;
if (log) {
log_debug("Already init logger feature");
} else {
switch (type) {
case LOGGER_TYPE_STDOUT:
log_info("debug via stdout");
log = new LoggerStdout();
break;
case LOGGER_TYPE_STDERR:
log_info("debug via stderr");
log = new LoggerStderr();
break;
case LOGGER_TYPE_SYSLOG:
log_info("debug via syslog");
log = new LoggerSyslog();
break;
default:
break;
}
}
return ret;
}
int logger_change_log_type(const int type)
{
logger_deinit();
return logger_init(type);
}
int logger_change_log_level(const int level)
{
if (log) {
return log->change_level(level);
}
return -1;
}
int logger_print_it(const uint32_t level, const char *format, ...)
{
int ret = -1;
if (!log || (level >= LOGGER_LEVEL_NUMS)) {
return ret;
}
char output[1024] = {0};
va_list arg;
va_start(arg, format);
vsprintf(output, format, arg);
switch (level) {
case LOGGER_LEVEL_DEBUG:
ret = log->debug(output);
break;
case LOGGER_LEVEL_INFO:
ret = log->info(output);
break;
case LOGGER_LEVEL_WARNING:
ret = log->warning(output);
break;
case LOGGER_LEVEL_ERROR:
ret = log->error(output);
break;
case LOGGER_LEVEL_CRITICAL:
ret = log->critical(output);
break;
default:
break;
}
va_end(arg);
return ret;
}
int logger_deinit()
{
if (log) {
delete log;
log = NULL;
}
return 0;
}