2

I am trying to limit the number of logs that are kept on my cloudstack management server. I am running log4j 1.2 and have recently added "<param name="MaxBackupIndex" value="31"/>" to my config (/etc/cloudstack/management/log4j-cloud.xml) to only keep 31 logs:

<appender name="FILE" class="org.apache.log4j.rolling.RollingFileAppender">
      <param name="Append" value="true"/>
      <param name="Threshold" value="TRACE"/>
      <rollingPolicy class="org.apache.log4j.rolling.TimeBasedRollingPolicy">
        <param name="FileNamePattern" value="/var/log/cloudstack/management/management-server.log.%d{yyyy-MM-dd}.gz"/>
        <param name="ActiveFileName" value="/var/log/cloudstack/management/management-server.log"/>
        <param name="MaxBackupIndex" value="31"/>
      </rollingPolicy>
      <layout class="org.apache.log4j.EnhancedPatternLayout">
         <param name="ConversionPattern" value="%d{ISO8601} %-5p [%c{1.}] (%t:%x) (logid:%X{logcontextid}) %m%n"/>
      </layout>
   </appender>

However all the logs are still there and I have run out of ideas. Does log4j not apply its archival policy to older logs? Is there anything else I need to change? Any suggestions would be appreciated.

Tom
  • 61

1 Answers1

1

For a start there is no 'rolling' package in the log4j 1.2 (which i know you are using;) ). Referring to a class in a package which is non existent may result in 'ClassNotFound Exceptions' because the class its looking for does not reside where you are telling it should be.

Also i would move MaxBackupIndex up from #rollingPolicy and add MaxFileSize parameter like so.

<appender name="FILE" class="org.apache.log4j.RollingFileAppender">
      <param name="Append" value="true"/>
      <param name="Threshold" value="TRACE"/>
      <param name="MaxBackupIndex" value="31"/>
      <param name="MaxFileSize" value="x" />

Edit:

the rolling package can be found in Apache Extras for log4j: https://logging.apache.org/log4j/extras/ whis is an additional jar file holding extra functionality. Standard API does not have rolling package.