I want the log to roll over as long as the application is running, but I want the log to start fresh when the application is restarted.
Updated: Based on erickson’s feedback, my appender looks like this:
<appender name='myRFA' class='org.apache.log4j.RollingFileAppender'> <param name='File' value='my-server.log'/> <param name='Append' value='false' /> <param name='MaxFileSize' value='10MB'/> <param name='MaxBackupIndex' value='10'/> <layout class='org.apache.log4j.PatternLayout'> <param name='ConversionPattern' value='%d{ISO8601} %p - %t - %c - %m%n'/> </layout> </appender>
I simply added the following line:
<param name='Append' value='false' />
It now truncates the base log file at startup, but it leaves the rolled files alone.
If you set the
appendparameter tofalse, the base log file will be ‘started fresh’ when the application restarts. Do you mean that you want any ‘rolled’ log files to be deleted too?