Implementing Rolling Log Files with log4j2

It is necessary to keep track of log traces, without having too big files (matter of transportation, if you communicate with a customer), it is necessary to configure a rolling appender in the logging framework. Here is an example with log4j2

Thanks to this configuration, the file will "roll" (when it is full, then a new file is created with an increment)

        <RollingRandomAccessFile name="logFile" fileName="/logs/appname/test/test.log" filePattern="appname-%d{MM-dd-yyyy}.log.gz"  append="true">
                <SizeBasedTriggeringPolicy size="20 MB"/>
            <DefaultRolloverStrategy max="200"/>

Previous Post Next Post