Solved

Clear rotated logs on startup in log4j using RollingFileAppender

Posted on 2010-08-20
7
1,864 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
7 Comments
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 200 total points
Comment Utility
You might need something custom for that
0
 

Author Comment

by:stev0931
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

Author Comment

by:stev0931
Comment Utility
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
Comment Utility
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
Comment Utility
There is no ready made way that log4j does this, but you could use a custom Configurator
0
 

Author Closing Comment

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

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now