1
votes

Below is the code i used to generate the log files using log4j and then roll it based on size. Files are getting generated, however the files are not rolling over based on Max File size. I heard in one post that we have to use apache-log4j-extras and am using apache-log4j-extras-1.2.17. I tried to roll over once 50KB has been reached, but its not rolling over. Can someone please let me know what could have gone wrong?

Am using log4j-1.2.17 and apache-log4j-extras-1.2.17 version of jar.

log4j.appender.Flows=org.apache.log4j.RollingFileAppender
log4j.appender.Flows.File=E:/Logs/Flows.log
log4j.appender.Flows.MaxFileSize=50KB
log4j.appender.Flows.MaxBackupIndex=2
log4j.appender.Flows.layout=org.apache.log4j.PatternLayout
log4j.appender.Flows.layout.ConversionPattern=%d %-5p - %c %x %m%n
2

2 Answers

3
votes

If you are using Apache Extras™ for Apache log4j™, you may want to use org.apache.log4j.rolling.RollingFileAppender:

log4j.appender.Flows=org.apache.log4j.rolling.RollingFileAppender  
log4j.appender.Flows.rollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy  
log4j.appender.Flows.rollingPolicy.maxIndex=2  
log4j.appender.Flows.triggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy  
log4j.appender.Flows.triggeringPolicy.MaxFileSize=51200  
log4j.appender.Flows.rollingPolicy.FileNamePattern=E:/Logs/Flows-%i.log  
log4j.appender.Flows.rollingPolicy.ActiveFileName=E:/Logs/Flows.log
log4j.appender.Flows.layout=org.apache.log4j.PatternLayout  
log4j.appender.Flows.layout.ConversionPattern=%d %-5p - %c %x %m%n  
0
votes

The problem appears to be caused by having the log4j*.jar in multiple levels of the class loader. E.g. once provided by Tomcat and a second time provided by a web app directly. Removing log4j from our WAR in a Tomcat installation solved the problem for us.

Doing so, we could avoid the use of log4j extras.