[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

Configuring LOG4CPLUS

Anirudh

11/25/2008 2:09:00 PM

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