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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…