-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathLogFromLog4cplus.cpp
executable file
·59 lines (58 loc) · 1.85 KB
/
LogFromLog4cplus.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
#include "LogFromLog4cplus.h"
#include <stdio.h>
namespace xlog{
int levels[XLOG_ALL]={
log4cplus::OFF_LOG_LEVEL,
log4cplus::FATAL_LOG_LEVEL,
log4cplus::ERROR_LOG_LEVEL,
log4cplus::WARN_LOG_LEVEL,
log4cplus::INFO_LOG_LEVEL,
log4cplus::DEBUG_LOG_LEVEL,
log4cplus::TRACE_LOG_LEVEL
};
ConfigureAndWatchThread *LogFromLog4cplus::watchdog_thread_ = NULL;
LogFromLog4cplus::LogFromLog4cplus(const char *instance) : imp_(Logger::getInstance(LOG4CPLUS_TEXT(instance))) {
}
void LogFromLog4cplus::init(const char *filename, bool isAuto) {
if (isAuto == false) {
PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT(filename));
} else if (watchdog_thread_==NULL) {
watchdog_thread_ = new ConfigureAndWatchThread(filename,5000);
} else {
delete watchdog_thread_;
watchdog_thread_ = NULL;
watchdog_thread_ = new ConfigureAndWatchThread(filename,5000);
}
}
void LogFromLog4cplus::destroy() {
if (watchdog_thread_ != NULL) {
delete watchdog_thread_;
watchdog_thread_ = NULL;
}
}
bool LogFromLog4cplus::is_enable_level(const XLOG_LEVEL l) {
log4cplus::LogLevel level=levels[l];
return imp_.isEnabledFor(level);
}
void LogFromLog4cplus::write_fmt(const XLOG_LEVEL l, const char *fmt, ...) {
va_list list;
va_start( list, fmt );
this->write_fmt(l,fmt,list);
va_end(list);
}
void LogFromLog4cplus::write_fmt(const XLOG_LEVEL l, const char *fmt, va_list list) {
#ifdef WIN32
#if (_MSC_VER < 1500)
#define vsnprintf _vsnprintf
#endif
#endif
log4cplus::LogLevel level = levels[l];
char buf[2048] = {0};
vsnprintf( buf, (size_t)2047, fmt, list);
imp_.forcedLog(level, buf, __FILE__, __LINE__);
}
void LogFromLog4cplus::write_buf(const XLOG_LEVEL l,const char *szBuf) {
log4cplus::LogLevel level=levels[l];
imp_.forcedLog(level, szBuf, __FILE__, __LINE__);
}
}