Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2086
  • 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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