Win a copy of Machine Learning with R: Expert techniques for predictive modeling this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

log4j - DailyRollingFileAppender - Deleting 14 day old files automatically

 
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..
 
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?
 
author
Posts: 3281
8
Mac OS X Eclipse IDE Java
  • 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

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Annu, for giving such a useful link..
  • 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
 
Sheriff
Posts: 24654
58
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.
 
Something must be done about this. Let's start by reading this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!