I have the following logging problem with several Java applications using log4j
for logging:
I want log files to be rotated daily, like
There's also a DailyRollingFileAppender
Edit: after reading this worrying statement:
DailyRollingFileAppender has been observed to exhibit synchronization issues and data loss. 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.RollingFileAppender.
from the above URL (which I never realized before), then the log4j-extras looks to be a better option.
You can perform your housekeeping in a separate script which can be cronned to run daily. Something like this:
find /path/to/logs -type f -mtime +7 -exec rm -f {} \;