You could manually trigger a rollover when the application starts up. We
do something similar in our application when the user wants to clear the
log files.

 

      log4cxx::LoggerPtr pLogger = log4cxx::Logger::getRootLogger();

      log4cxx::AppenderPtr pAppender =
pLogger->getAppender(LOG_FILEAPPENDER_NAME);

      

      if (pAppender)

      {

            // Down cast so we have access tot he rolling file
appender's methods

            log4cxx::helpers::ObjectPtrT<log4cxx::RollingFileAppender>
pRFAppender = pAppender;

            log4cxx::helpers::Pool pool;

            pRFAppender->rollover(pool);

      }

 

That will trigger a log file rollover. So, you could configure the
appender with Append = true and then trigger a rollover when the
application first starts up. You might need a special case when the
application starts for the first time if you don't want an extra empty
log file, but hope this gets you closer.

 

-Chris

 

________________________________

From: Peter Steele [mailto:[EMAIL PROTECTED] 
Sent: Thursday, August 14, 2008 10:24 AM
To: Log4CXX User
Subject: RollingFileAppender question

 

We are using a RollingFileAppender defined as follows:

 

   <appender name="FILE" class="org.apache.log4j.RollingFileAppender">

       <param name="maxFileSize" value="200MB" />

       <param name="maxBackupIndex" value="12" />

       <param name="File" value="${LOGNAME}" />

       <param name="Append" value="false"/>

       <layout class="org.apache.log4j.PatternLayout">

           <param name="ConversionPattern"

               value="%d{MM-dd HH:mm:ss.SSS} %5p %c{1} - %m%n" />

       </layout>

   </appender>

 

This works the way we want with one exception: When our app that uses
this appender starts up it overwrites the existing log file. This is of
course because we have Append set to false. What we'd like to have
happen is that if there is an existing log file have a rollover occur
immediately so that no log data is lost. Can that be setup or is our
only option is to set Append to true?

 

Reply via email to