-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.cpp
64 lines (53 loc) · 1.3 KB
/
log.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
#include <map>
#include <string>
#include <stdexcept>
#include "log.h"
namespace log {
static std::map<std::string, log_level_t> log_level_map_create(void)
{
std::map<std::string, log_level_t> ret;
ret["quite"] = LOG_NONE;
ret["no"] = LOG_NONE;
ret["none"] = LOG_NONE;
ret["off"] = LOG_NONE;
ret["Quite"] = LOG_NONE;
ret["No"] = LOG_NONE;
ret["None"] = LOG_NONE;
ret["Off"] = LOG_NONE;
ret["error"] = LOG_ERROR;
ret["Error"] = LOG_ERROR;
ret["err"] = LOG_ERROR;
ret["Err"] = LOG_ERROR;
ret["warn"] = LOG_WARN;
ret["warning"] = LOG_WARN;
ret["Warn"] = LOG_WARN;
ret["Warning"] = LOG_WARN;
ret["info"] = LOG_INFO;
ret["Info"] = LOG_INFO;
ret["debug"] = LOG_DEBUG;
ret["Debug"] = LOG_DEBUG;
ret["all"] = LOG_ALL;
ret["All"] = LOG_ALL;
ret["ALL"] = LOG_ALL;
return ret;
}
const static std::map<std::string, log_level_t>
log_level_map = log_level_map_create();
static log_level_t log_level = LOG_WARN;
void set_log_level(const char *level)
{
try {
log_level = log_level_map.at(level);
} catch (const std::out_of_range &oor) {
std::string err("No such log level: `");
err += level;
throw std::logic_error(err + "'");
}
}
log_level_t curr_log_level(void)
{
return log_level;
}
log_stream err(LOG_ERROR), warn(LOG_WARN), info(LOG_INFO),
debug(LOG_DEBUG), all(LOG_ALL);
}; /* namespace log */