1

We have a business requirement to keep last 7 days log Can we use log4j to delete old 7 days log.

We are using

log4j.appender.stdout=org.apache.log4j.RollingFileAppender

Please let me know.

Mariusz Jamro
  • 30,615
  • 24
  • 120
  • 162
Jagaran
  • 176
  • 1
  • 4
  • 10

1 Answers1

1

You could use an enhanced version of the DailyRollingFileAppender Use MaxBackupIndex in DailyRollingFileAppender -log4j

Otherwise you could create a cron job that just deletes the logs over a certain age:

find /your/log/dir -name "*.log" -ctime +7 -exec rm {} \;
Community
  • 1
  • 1
Ben Flynn
  • 18,524
  • 20
  • 97
  • 142