-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLogSys.cpp
More file actions
80 lines (62 loc) · 1.64 KB
/
Copy pathLogSys.cpp
File metadata and controls
80 lines (62 loc) · 1.64 KB
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
/*
* LogSys.cpp
*
* Created on: Aug 15, 2012
* Author: xieliang
*/
#include "LogSys.h"
#include "allyes-log.h"
#include "common.h"
using namespace std;
using namespace boost;
LogSys& LogSys::getInstance() {
static LogSys the_one;
return the_one;
}
LogSys::LogSys() {
}
LogSys::~LogSys() {
if(logger_) {
logger_.reset();
}
}
bool LogSys::initialize(const string& config_file) {
LogConfig config;
if(config_file.empty()) {
LOG_TO_STDERR("No log config file specified. The default setting will be used!");
}
else {
LOG_TO_STDERR("Opening file <%s> to get log config...", config_file.c_str());
if(!config.parseConfig(config_file)) {
LOG_TO_STDERR("Errors happened when read the log config file!");
return false;
}
}
unsigned long dest = static_cast<unsigned long>(LOG_DEFAULT_LOG_DEST);
config.getUnsigned(TEXT_LOG_DESTINATION, dest);
logger_ = Logger::createLoggerInterface(ENUM_LOG_TYPE(dest));
if (NULL == logger_) {
LOG_TO_STDERR("Failed to create the logger interface!");
return false;
}
if (!logger_->config(config)) {
LOG_TO_STDERR("Failed to config the log system");
return false;
}
if (!logger_->open()) {
LOG_TO_STDERR("Failed to open the log system");
return false;
}
LOG_TO_STDERR("Log system initialized OK!");
return true;
}
void LogSys::log(const string& msg, ENUM_LOG_LEVEL level) {
if(logger_) {
logger_->log(msg, level);
}
}
void LogSys::setLevel(ENUM_LOG_LEVEL level) {
if(logger_) {
logger_->setLevel(level);
}
}