I'm using log4j 1.2.15 and I wonder if someone has a remedy to the annoying file renaming strategy log4j is using.
I'll try to explain: I am using the following RollingFileAppender that creates 11 log files each one 3KB size.
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.File=server.log
log4j.appender.logfile.MaxFileSize=3KB
log4j.appender.logfile.MaxBackupIndex=10
The problem is that while creating a new log file, log4j creates server.log.1, server.log.2 etc...
Can I configure log4j to keep the ".log" suffix, and create for instance server.1.log?
Thanks in advance Guy
renameTo() to change the filename.
You can rename the log4j properties file to any other name and then through your code, you can use the PropertyConfigurator to load that file.
RollingFileAppender extends FileAppender to backup the log files when they reach a certain size. The log4j extras companion includes alternatives which should be considered for new deployments and which are discussed in the documentation for org. apache. log4j. rolling.
I'm doing this using an xml configuration (might be possible without) and Apache Extras Companion™ for Apache log4j™ (an extra library for log4j). I don't think this works without the extra's, but it might.
The key is to use the FileNamePattern
.
<appender name="logger" class="org.apache.log4j.rolling.RollingFileAppender">
<rollingPolicy class="org.apache.log4j.rolling.FixedWindowRollingPolicy">
<param name="FileNamePattern" value="/server.%i.log" />
<param name="MaxIndex" value="10" />
</rollingPolicy>
<triggeringPolicy class="org.apache.log4j.rolling.SizeBasedTriggeringPolicy">
<param name="MaxFileSize" value="3000" />
</triggeringPolicy>
</appender>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With