logging-log4cxx-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Curt Arnold <carn...@apache.org>
Subject Re: using RollingFileAppender
Date Mon, 02 Jun 2008 16:59:30 GMT

On Jun 2, 2008, at 7:13 AM, Madhu Gowda wrote:

> Hi all,
>
>
> I am trying to make use of RollingFileAppender.
>
> My code is as follows:
>
>
> LoggerPtr logger( Logger::getLogger("CustomLogger"));
>
>
> RollingFileAppender *pAppender = new RollingFileAppender();
>

Instead use:

RollingFileAppenderPtr pAppender(new RollingFileAppender());

Otherwise, reference counts are likely to be mismanaged.
> pAppender- 
> >setName( log4cxx::helpers::Transcoder::decode("TestAppender"));
>
> pAppender- 
> >setFile( log4cxx::helpers::Transcoder::decode("TestLogFile.txt"));
>
> pAppender->setAppend( true);
>
> pAppender->setMaxBackupIndex( 5);
>
> pAppender->setMaxFileSize( log4cxx::helpers::Transcoder::decode("5  
> KB"));
>
> pAppender->setLayout( new  
> PatternLayout( log4cxx::helpers::Transcoder::decode("%d [%t] %-5p %c  
> - %l - %m%n")));
>
>

If an appender (also applies to layouts, etc) is created with the  
default constructor, the activateOptions() method must be called after  
the properties are set.

Pool p;
pAppender->activateOptions(p);


>
> logger->addAppender( fAppender);
>
>
> This code is giving the error as:
>
> "No output stream or file set for the appender named TestAppender"
>
>
> But, if I create the appender as:
>
>
> RollingFileAppender *pAppender = new RollingFileAppender( new  
> PatternLayout( log4cxx::helpers::Transcoder::decode("%d %-5p %c - %l  
> - %m%n")),
>
>  log4cxx::helpers::Transcoder::decode("TestLogFile.txt"));
>
>
> and I set the MaxBackupIndex and MaxFileSize as follows:
>
>
> pAppender->setMaxBackupIndex( 5);
>
> pAppender->setMaxFileSize( log4cxx::helpers::Transcoder::decode("5  
> KB"));
>
>
> It works fine but, the new log file is not getting created after the  
> MaxFileSize (5 KB) is reached, the log messages are just getting  
> appended to same log file ().
>

When an constructor takes arguments, it has a call to  
activateOptions() to make it ready for action upon construction.   
However, any changes that occur after that point would need an call to  
activateOptions() to ensure that the changes are reflected in the  
behavior.

>
> Please, suggest what is going wrong here.
>
>
> Thanks & Regards,
>
> Madhu Gowda
>
>
>


Mime
View raw message