I have the following logging problem with several Java applications using log4j
for logging:
I want log files to be rotated daily, like
log.2010-09-10
log.2010-09-09
log.2010-09-08
log.2010-09-07
log.2010-09-06
log.2010-09-05
log.2010-09-04
But for data security reasons we are not allowed to keep log files for longer than seven days at my company. So the generation of the next next log file log.2010-09-11
should trigger the deletion of log.2010-09-04
. Is it possible to configure such a behaviour with log4j
? If not, do you know another elegant solution for this kind of logging problem?
The class
DailyRollingFileAppender
uses the DatePattern option to specify the rolling schedule. This pattern should follow theSimpleDateFormat
conventions from Std. Ed. v1.4.2. So, we have to useE
option (Day in week). For example:See more about
DailyRollingFileAppender
class fromlog4j
javadoc here. Unfortunately the Java 1.4.2 documentation is no longer online, but you can download a copy here.