File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other Open Source Projects and the fly likes log4j - DailyRollingFileAppender -  Deleting 14 day old  files automatically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "log4j - DailyRollingFileAppender -  Deleting 14 day old  files automatically" Watch "log4j - DailyRollingFileAppender -  Deleting 14 day old  files automatically" New topic
Author

log4j - DailyRollingFileAppender - Deleting 14 day old files automatically

RajeshK Joshi
Greenhorn

Joined: Feb 05, 2004
Posts: 2
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

Joined: Jul 17, 2009
Posts: 19
I need the same functionality. Is there no other way except writing code for deleting the files?
Martijn Verburg
author
Bartender

Joined: Jun 24, 2003
Posts: 3274
    
    5

You'll need to write your own functionality yes.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Annu Vinayak
Greenhorn

Joined: Jul 17, 2009
Posts: 19
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

Joined: Jul 19, 2009
Posts: 110
Thanks Annu, for giving such a useful link..


Roll with punchers, there is always tomorrow.
Techie Blog -- http://jtanzy.blogspot.com/
Arun GopalakrishanaPillai Chandrikamma
Greenhorn

Joined: Oct 09, 2013
Posts: 1
Hi Anuu
The link you provided is break can you please help me to solve the same issue i am facing

Arun
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18113
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: log4j - DailyRollingFileAppender - Deleting 14 day old files automatically
 
Similar Threads
WARN level is not working
Problems with DailyRollingFileAppender in log4j
Log4j created file not able to delete while testing my application??
log4j config file setup
How to set maxsize of logfile