Solved

Clear rotated logs on startup in log4j using RollingFileAppender

Posted on 2010-08-20
7
1,988 Views
Last Modified: 2012-05-10
I have my log4j config set up with MaxBackupIndex=1.  When I close down the app then bring it up, it clears the main log file (which is what I want), but does not delete any rolled files from the previous run (this is what I want to change).

For example, if the log file is gui.log and I close the gui when gui.log and gui.log.1 exist, then I bring up the GUI again, I want gui.log cleared (which is happening) and gui.log.1 deleted (what I'm trying to figure out how to do).

Any suggestions would be most appreciated.  Thanks!
0
Comment
Question by:stev0931
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 200 total points
ID: 33485465
You might need something custom for that
0
 

Author Comment

by:stev0931
ID: 33485958
Doing something custom is always an option, but I'd prefer to use something via the log4j API first for reduced system fragility.
0
 
LVL 16

Expert Comment

by:Valeri
ID: 33486456
try to set parameter Append to false. I think that it will erase the old files too...?!
If you don't want old files, then set MaxBackupIndex=0
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:stev0931
ID: 33486522
Setting append to false results in the main log file (e.g. gui.log) being cleared at startup.  Unfortunately, it does not impact the gui.log.1.  Setting MaxBackupIndex to 0 will get me no log rolling at all.  I need to have log rolling - I just need to delete old rolled logs on application startup.
0
 
LVL 92

Accepted Solution

by:
objects earned 300 total points
ID: 33490086
log4j only manages the file it is currently logging to.
Usual practice is to manage logs externally to log4j eg. using cron or doing it in your startup script.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 33490646
There is no ready made way that log4j does this, but you could use a custom Configurator
0
 

Author Closing Comment

by:stev0931
ID: 33491530
Thanks!  Not what I wanted to hear, but sometimes the answer just works out that way ;)
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question