How can I get log4j to delete old rotating log files?

skiphoppy picture skiphoppy · Jun 26, 2009 · Viewed 112.1k times · Source

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.

Answer

Jared Oberhaus picture Jared Oberhaus · Jun 26, 2009

RollingFileAppender does this. You just need to set maxBackupIndex to the highest value for the backup file.