Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2187
  • Last Modified:

Clear rotated logs on startup in log4j using RollingFileAppender

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
stev0931
Asked:
stev0931
2 Solutions
 
CEHJCommented:
You might need something custom for that
0
 
stev0931Author Commented:
Doing something custom is always an option, but I'd prefer to use something via the log4j API first for reduced system fragility.
0
 
ValeriCommented:
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
stev0931Author Commented:
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
 
objectsCommented:
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
 
CEHJCommented:
There is no ready made way that log4j does this, but you could use a custom Configurator
0
 
stev0931Author Commented:
Thanks!  Not what I wanted to hear, but sometimes the answer just works out that way ;)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now