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
  • 51
  • 1
  • 5

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.

Maciej Cygan
  • 137
  • 8
  • Actually there is "rolling package" -> https://logging.apache.org/log4j/extras/apidocs/org/apache/log4j/rolling/RollingFileAppender.html – Tom Mar 31 '17 at 09:44
  • Unfortunately, making the changes you have suggested did not work so I did some more checking around. You should not specify MaxFileSize if you are implementing TimeBasedRollingPolicy. Any more suggestions anyone? :) – Tom Mar 31 '17 at 09:51
  • @Tom not in standard log4j, rolling seems to be found in 'extras' for log4j. – Maciej Cygan Mar 31 '17 at 10:02
  • it turns out I have apache-log4j-extras-1.2.17.jar installed :) – Tom Mar 31 '17 at 11:23
  • @Tom then it has to work... unless there is some sort of permission issue. or log4j is not runnig the file you think it is. – Maciej Cygan Mar 31 '17 at 12:28