How can I get log4j to delete old rotating log files? I know I can set up automated jobs (cron for UNIX and scheduled task for Windows), but I want it cross platform, and I want it in our application's log configuration as a part of our application, rather than in separate code outside in OS specific scripting languages. Our application is not written in OS scripting languages, and I don't want to do this part of it in them.
相关问题
- convert logback.xml to log4j.properties
- Rotating an Object properly around a pivot point g
- logging static methods in a parent class
- Rotate a door in both directions in Unity
- Wrap log4j or create custom logger?
相关文章
- SVG circle starting point
- Can IntelliJ create hyperlinks to the source code
- how can I disable output to log4j.rootLogger?
- Log4j2 using {} against using %d or %s
- How do I redirect a javaw.exe console output to a
- log4j: Standard way to prevent repetitive log mess
- Rotate image in Quartz? Image is upside down! (iPh
- Rotate image around x, y, z axis in OpenCV
RollingFileAppender does this. You just need to set maxBackupIndex to the highest value for the backup file.
Logs rotate for a reason, so that you only keep so many log files around. In log4j.xml you can add this to your node:
The value tells log4j.xml to only keep 20 rotated log files around. You can limit this to 5 if you want or even 1. If your application isn't logging that much data, and you have 20 log files spanning the last 8 months, but you only need a weeks worth of logs, then I think you need to tweak your log4j.xml "MaxBackupIndex" and "MaxFileSize" params.
Alternatively, if you are using a properties file (instead of the xml) and wish to save 15 files (for example)
There is no default value to control deleting old log files created by DailyRollingFileAppender. But you can write your own custom Appender that deletes old log files in much the same way as setting maxBackupIndex does for RollingFileAppender.
Simple instructions found here
From 1: