我是新来log4cxx的。我尝试为附加器设置一个阈值。在我的代码中,我获得了附加器终端(它将在我的xterm窗口中写入)。
log4cxx::LoggerPtr loggerLog4cxx(log4cxx::Logger::getRootLogger());
log4cxx::AppenderPtr app = loggerLog4cxx->getAppender("TERMINAL");
我会将级别设置为关闭或全部设置到此附加器。我已经看到AppenderSkeleton类有一个setThreshold(log4cxx::Level)方法。但我不知道如何将我的附加器转换为AppenderSkeleton。
谢谢你的帮忙!
发布于 2012-10-10 14:47:34
我已经为我的开发案例找到了一个解决方案。我将获得我所有的附加器,并测试每个附加器。我需要知道它们是控制台还是文件附加器。
log4cxx::LoggerPtr loggerLog4cxx(log4cxx::Logger::getRootLogger());
log4cxx::AppenderList appList = loggerLog4cxx->getAllAppenders ();
for(log4cxx::AppenderList::iterator it=appList.begin(); it!=appList.end(); it++) {
log4cxx::ConsoleAppenderPtr console = *it;
if( console ) {
console->setThreshold( log4cxx::Level::getOff() );
} else {
log4cxx::FileAppenderPtr file = *it;
if ( file ) {
file->setThreshold( log4cxx::Level::getOff() );
}
}
}
发布于 2012-10-09 22:04:59
您在记录器级别设置级别,而不是在附加器级别。查看文档- http://logging.apache.org/log4cxx/
logger->setLevel(log4cxx::Level::getInfo());
所以在你的例子中:
loggerLog4cxx->setLevel(log4cxx::Level::getInfo());
https://stackoverflow.com/questions/12801597
复制相似问题