Sample Log4j2 XML configuration for rolling file and console

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
<Loggers>
<Root level="TRACE">
<AppenderRef ref="RollingFileAppender" level="INFO" />
<appender-ref ref="Console" level="TRACE" />
</Root>
</Loggers>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t]
%highlight{%level}{FATAL=bg_red, ERROR=red, WARN=yellow, INFO=green, DEBUG=blue} - %msg%n" />
</Console>
<RollingFile name="RollingFileAppender" fileName="logs/goyun.info.log" filePattern="logs/$${date:yyyy-MM}/email-%d{MM-dd-yyyy}-%i.log.zip">
<PatternLayout>
<Pattern>%d [%t] %p %c - %m%n</Pattern>
</PatternLayout>
<Policies>
<OnStartupTriggeringPolicy />
<TimeBasedTriggeringPolicy />
<SizeBasedTriggeringPolicy size="48 MB" />
</Policies>
<DefaultRolloverStrategy max="8" />
</RollingFile>
</Appenders>
</Configuration>

Comments