Rolling logs by both size and time

后端 未结 3 1197
粉色の甜心
粉色の甜心 2020-12-16 21:06

I use RollingFileAppender of log4j 1.2.16, which rolls log files, when they reach a certain size. Now I would like to roll log files daily and<

3条回答
  •  死守一世寂寞
    2020-12-16 21:44

    There are indeed two options:

    1. use LogBack with its size and time triggering policy: http://logback.qos.ch/manual/appenders.html#SizeAndTimeBasedFNATP
    2. there is TimeAndSizeRollingAppender for Log4J from here: http://www.simonsite.org.uk/

    Keep in mind that both options use file renames. Consider this carefully if there's another script automatically moving these files. File rename is risky when two processes deal with the same file.

    My suggestion is to directly write to immutable log file name in the pattern: myapp-{dd.MM.yyyy}.{X}.log. That way "rolling" is simply closing one file and opening a new one. No renames. No background threads.

提交回复
热议问题