• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

log4j - DailyRollingFileAppender - Deleting 14 day old files automatically

 
RajeshK Joshi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
//----- property file snippet
..
..
log4j.appender.rollingFile=org.apache.log4j.DailyRollingFileAppender
log4j.appender.rollingFile.File=mylog
..
..
//-----------------------------
I am using DailyRollingFileAppender which works fine.. Is there any 'property' that can be set so that files older than x days are removed automatically?
I cannot use RollingFileAppender which would have done the job for me..
 
Annu Vinayak
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need the same functionality. Is there no other way except writing code for deleting the files?
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll need to write your own functionality yes.
 
Annu Vinayak
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your reply. I already found a very nice article which helped me to resolve this issue. Please refer the following for this:

http://blog.justtechnologies.ca/2008/07/improving-log4j-dailyrollingfileappende.html

 
Tanzy Akhtar
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Annu, for giving such a useful link..
 
Arun GopalakrishanaPillai Chandrikamma
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anuu
The link you provided is break can you please help me to solve the same issue i am facing

Arun
 
Paul Clapham
Sheriff
Posts: 21114
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of trying to modify the appender so that it deletes old files, why don't you just write a separate piece of code which you run daily? Since the java.io.File class contains methods for getting all files in a directory and finding out when they were last changed, it's very easy to write something which deletes all files in a directory which are more than X days old.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic