Log4j configuration(Size Based) not working

Ashu picture Ashu · Feb 27, 2013 · Viewed 12.1k times · Source

I have my application for which the below entry is done in Log4j properties file.Size based rolling is not working for this application. File does not rollover at 5 MB and the application keeps on logging and making it in GB. In one run approximately 6 MB of log is generated.The application runs multiple times a day.

Can someone help in pointing out where I am doing a mistake?

# SampleApp configuration
log4j.category.com.ibm.hmel.hwmmphdya=INFO, SampleApp  
log4j.additivity.com.ibm.hmel.hwmmphdya=false  
log4j.appender.SampleApp =org.apache.log4j.rolling.RollingFileAppender  
log4j.appender.SampleApp.File=S:/FIH/LOG/SAMPLE_APP_01/SAMPLE_APP_01.log  
log4j.appender.SampleApp.layout=org.apache.log4j.PatternLayout  
log4j.appender.SampleApp.layout.ConversionPattern=%-21d{dd-MMM-yyyy HH:mm:ss} [%t] %-5p %c %x - %m%n  

log4j.appender.SampleApp.RollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy
log4j.appender.SampleApp.RollingPolicy.FileNamePattern=S:/HIF/LOG/SAMPLE_APP_01  /SAMPLE_APP_01.log.%i.zip
log4j.appender.SampleApp.RollingPolicy.MinIndex=1
log4j.appender.SampleApp.RollingPolicy.MaxIndex=10
log4j.appender.SampleApp.TriggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy
log4j.appender.SampleApp.TriggeringPolicy.MaxFileSize=5242880

Answer

Mubashar picture Mubashar · Jul 11, 2014

Following works for me

log4j.rootLogger=TRACE, Roller

log4j.appender.Roller=org.apache.log4j.rolling.RollingFileAppender
log4j.appender.Roller.RollingPolicy=org.apache.log4j.rolling.FixedWindowRollingPolicy  
log4j.appender.Roller.RollingPolicy.maxIndex=13
log4j.appender.Roller.TriggeringPolicy=org.apache.log4j.rolling.SizeBasedTriggeringPolicy  
log4j.appender.Roller.TriggeringPolicy.MaxFileSize=26214400
log4j.appender.Roller.RollingPolicy.FileNamePattern=j_log_%i.log
log4j.appender.Roller.RollingPolicy.ActiveFileName=j_log_0.log
log4j.appender.Roller.layout=org.apache.log4j.PatternLayout
log4j.appender.Roller.layout.ConversionPattern=%d [%t] %-5p %c - %m%n