1

I'm new in log4cxx. I try to set a threshold to an appender. In my code, I get the appender TERMINAL (it will write in my xterm windows).

log4cxx::LoggerPtr loggerLog4cxx(log4cxx::Logger::getRootLogger());
log4cxx::AppenderPtr app = loggerLog4cxx->getAppender("TERMINAL");

I will set the level OFF or ALL to this appender. I have seen that AppenderSkeleton class have a method setThreshold(log4cxx::Level). But I don't know how to convert my Appender to an AppenderSkeleton.

Thanks for your help!

Shaina
  • 51
  • 5

2 Answers2

3

I have found a solution for my development case. I will get all my appender, and test each of them. I need to know if they are console or file appender.

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() );
        }
    }
}
Shaina
  • 51
  • 5
0

You set level at logger level, not appender. Look at the documentation - http://logging.apache.org/log4cxx/

logger->setLevel(log4cxx::Level::getInfo());

So in your case:

loggerLog4cxx->setLevel(log4cxx::Level::getInfo());

DimaA6_ABC
  • 578
  • 4
  • 15
  • But if you have for example loggers: logger1 set to ALL, logger2 set to Error , and two appenders (one console, one file). At a time, You want in console only Error logs but keep all configurated log in the file. You must to set a threshold in you console appender. – Shaina Oct 09 '12 at 14:43