How to configure a log4j file appender which rolls the log file every 15 minutes

前端 未结 5 2097
孤独总比滥情好
孤独总比滥情好 2020-12-06 13:01

I understand that i can use a DailyRollingFileAppender to roll the log file every month, day, half-day, hour or minute. But how can i configure log4j to roll the log file ev

5条回答
  •  甜味超标
    2020-12-06 13:03

    The Javadoc for DailyRollingFileAppender in Log4J indicates that the time-based rolling only occurs on unit-based rollovers (day, week, month, etc.). That would mean the closest you could get with that pattern is '.'yyyy-MM-dd-HH-mm, which would roll over every minute.

    My recommendations would be to do one of the following:

    • Since you're running on a fixed interval, write a custom FileAppender that uses logic borrowed from DailyRollingFileAppender to make the computation
    • If you have some flexibility, switch from Log4J to LOGBack, and write a custom RollingPolicy that uses logic borrowed from the LOGBack time calculations (which will be very similar to the ones in Log4J)

    By the way, if you choose the latter, I'd recommend that you consider coding to the SLF4J API, and use LOGBack (or Log4J) as the underlying implementation.

提交回复
热议问题