Configuring LOG4CPLUS

A

Anirudh

Hi,

In a new project need to change the configuration of LOG4CPLUS
Earlier logging laytout, appender info etc. was in a static file and I
would call
Main.cpp
log4cplus::propertyConfigurator::doConfigure(logConfPathName);

After that each of my class had logger as a private member
e.g.

A.h
class A{
private:
static log4cplus::Logger logger;
};

A.cpp
log4cplus::Logger A::logger = log4cplus::Logger::getInstance
("ClassA");

Each class would use configuration property set by doConfigure and log
properly

Now I want to set the configuration manually as
e.g
SharedAppenderPtr fileAppender( new RollingFileAppender
("myLogFile.<timestamp>.log")) ;
fileAppender->setName("RollingFileAppender") ;
fileAppender->setThreshold(DEBUG_LOG_LEVEL);
std::auto_ptr<Layout> fileLayout = std::auto_ptr<Layout>(new
log4cplus::patternLayout("%d{%d %H:%M:%S} [%t] %-5p %c
[%L]: %m%n"));
fileAppender->setLayout( fileLayout );
logger.addAppender(fileAppender);

but this works only for the 'logger' I saying 'logger.addAppender' and
not for other loggers in other classes (as was happening earlier. Is
there a way to set the appender info on global level?

Also, I want log4cplus to create files with timestamp on every
initialization. Is there a way to do that? or I have specify from my
program everytime the file name?

Thanks
Anirudh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top