Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logback - cleanHistoryOnStart does not work

I have an application that runs on several servers which have been running for a few months with a java application that uses logback. Turns out we forgot to limit the history size.

I configured the following params:

 - maxHistory: 10
 - cleanHistoryOnStart: true

I redeployed the app but when it started, the files remained and haven't been deleted.

Shouldn't this configuration make sure that the files are deleted upon startup? What would be the way to do it?

like image 541
Avi Avatar asked Nov 18 '22 22:11

Avi


1 Answers

It's an old question but in case someone else struggles with this, here are some possible reasons this could happen:

  • the maxHistory value means something unexpected. From Logback documentation:

    For example, if you specify monthly rollover, and set maxHistory to 6, then 6 months worth of archives files will be kept with files older than 6 months deleted.

  • the chosen appender does not support the parameter.
  • spelling error, eg clearHistoryOnStart.
  • old version of Logback; cleanHistoryOnStart was introduced in 1.0.1

In the last 3 cases an error should be logged somewhere, reading:

Logback file error : no applicable action for [cleanHistoryOnStart], current pattern is [...]

If you're not sure if you're checking the right place, spell it wrong by intention and hunt the log. Then correct the misspelling and check if the error is still there (this time because it's invalid).

like image 104
ImpressiveStoneStatue Avatar answered Jan 05 '23 01:01

ImpressiveStoneStatue