Skip to content
Advertisement

DailyRollingFileAppender alternative in Log4j 2x

DailyRollingFileAppender was removed in Log4j 2x. What should be used instead?

Advertisement

Answer

Use a RollingFile 1 with TimeBasedTriggeringPolicy 2. e.g.:

<RollingFile name="RollingFile" 
             fileName="/tmp/app.log"
             filePattern="/tmp/app%d{yyyy-MM-dd}.log">
    <PatternLayout pattern="%d %p %c{1.} [%t] %m%n" />
    <TimeBasedTriggeringPolicy />
</RollingFile>

See more in Apache Log4j 2 User’s Guide [PDF].


Notes

  1. org.apache.logging.log4j.core.appender.RollingFileAppender
  2. org.apache.logging.log4j.core.appender.rolling.TimeBasedTriggeringPolicy
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement