Log4j2配置(异步记录器方式)
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN" monitorInterval="30">
<Properties>
<Property name="LOG_PATTERN">
%d{yyyy-MM-dd HH:mm:} %5p ${hostName} --- [%15.15t] %l : %m%n
</Property>
</Properties>
<Appenders>
<Console name="Console" target="SYSTEM_OUT" follow="true">
<PatternLayout pattern="${LOG_PATTERN}"/>
</Console>
<RollingRandomAccessFile name="RollingRandomAccessFile"
fileName="logs/"
filePattern="logs/app-%d{yyyy-MM-dd}.log">
<PatternLayout pattern="${LOG_PATTERN}"/>
<Policies>
<TimeBasedTriggeringPolicy interval="1" modulate="true" />
<SizeBasedTriggeringPolicy size="10MB" />
</Policies>
<!-- Max 10 files will be created everyday -->
<DefaultRolloverStrategy max="10">
<Delete basePath="logs" maxDepth="10">
<!-- Delete all files older than 30 days -->
<IfLastModified age="30d" />
</Delete>
</DefaultRolloverStrategy>
</RollingRandomAccessFile>
<Async name="AsyncRollingRandomAccessFile">
<AppenderRef ref="RollingRandomAccessFile" />
</Async>
</Appenders>
<Loggers>
<Logger name="" level="debug" additivity="false">
<AppenderRef ref="Console" />
<AppenderRef ref="AsyncRollingRandomAccessFile" />
</Logger>
<Root level="info">
<AppenderRef ref="Console" />
<AppenderRef ref="AsyncRollingRandomAccessFile" />
</Root>
</Loggers>
</Configuration>