12 #include <boost/lexical_cast.hpp>
14 #include <log4cplus/logger.h>
33 LoggerLevelImpl::convertFromBindLevel(
const Level& level) {
36 static const log4cplus::LogLevel log4cplus_levels[] = {
37 log4cplus::NOT_SET_LOG_LEVEL,
38 log4cplus::DEBUG_LOG_LEVEL,
39 log4cplus::INFO_LOG_LEVEL,
40 log4cplus::WARN_LOG_LEVEL,
41 log4cplus::ERROR_LOG_LEVEL,
42 log4cplus::FATAL_LOG_LEVEL,
43 log4cplus::OFF_LOG_LEVEL
47 BOOST_STATIC_ASSERT(
static_cast<int>(
DEFAULT) == 0);
48 BOOST_STATIC_ASSERT(
static_cast<int>(
DEBUG) == 1);
49 BOOST_STATIC_ASSERT(
static_cast<int>(
INFO) == 2);
50 BOOST_STATIC_ASSERT(
static_cast<int>(
WARN) == 3);
51 BOOST_STATIC_ASSERT(
static_cast<int>(
ERROR) == 4);
52 BOOST_STATIC_ASSERT(
static_cast<int>(
FATAL) == 5);
53 BOOST_STATIC_ASSERT(
static_cast<int>(
NONE) == 6);
64 LogLevel newlevel =
static_cast<int>(DEBUG_LOG_LEVEL -
66 return (
static_cast<log4cplus::LogLevel
>(newlevel));
74 return (log4cplus_levels[level.
severity]);
81 LoggerLevelImpl::convertToBindLevel(
const log4cplus::LogLevel loglevel) {
85 if (loglevel <= log4cplus::NOT_SET_LOG_LEVEL) {
88 }
else if (loglevel <= log4cplus::DEBUG_LOG_LEVEL) {
94 static_cast<int>(log4cplus::DEBUG_LOG_LEVEL) -
95 static_cast<int>(loglevel);
103 }
else if (loglevel <= log4cplus::INFO_LOG_LEVEL) {
106 }
else if (loglevel <= log4cplus::WARN_LOG_LEVEL) {
109 }
else if (loglevel <= log4cplus::ERROR_LOG_LEVEL) {
112 }
else if (loglevel <= log4cplus::FATAL_LOG_LEVEL) {
123 LoggerLevelImpl::logLevelFromString(
const log4cplus::tstring& level) {
125 std::string name = level;
126 size_t length = name.size();
132 return (NOT_SET_LOG_LEVEL);
135 if (strncasecmp(name.c_str(),
"DEBUG", 5) == 0) {
142 return (DEBUG_LOG_LEVEL);
152 int dbglevel = boost::lexical_cast<int>(name.substr(5));
164 return convertFromBindLevel(
Level(
DEBUG, dbglevel));
166 catch (boost::bad_lexical_cast&) {
168 return (NOT_SET_LOG_LEVEL);
175 return (NOT_SET_LOG_LEVEL);
182 #if LOG4CPLUS_VERSION < LOG4CPLUS_MAKE_VERSION(2, 0, 0)
187 LoggerLevelImpl::logLevelToString(log4cplus::LogLevel level) {
188 Level bindlevel = convertToBindLevel(level);
194 if ((severity ==
DEBUG) &&
206 LoggerLevelImpl::init() {
209 LogLevelManager& manager = getLogLevelManager();
212 manager.pushFromStringMethod(LoggerLevelImpl::logLevelFromString);
213 manager.pushToStringMethod(LoggerLevelImpl::logLevelToString);