log4j2常用配置

<?xml version="1.0" encoding="UTF-8"?>
<!--设置log4j2的自身log级别为warn-->
<configuration status="warn">

<appenders>
<console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
</console>

<RollingFile name="RollingFileALL" fileName="/home/app-logs/xxx/all.log"
filePattern="/home/app-logs/xxx/$${date:yyyy-MM}/all-%d{yyyy-MM-dd}-%i.log">
<Filters>
<ThresholdFilter level="DEBUG"/>
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="ACCEPT"/>
<ThresholdFilter level="WARN" onMatch="ACCEPT" onMismatch="ACCEPT"/>
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="ACCEPT"/>
</Filters>
<PatternLayout pattern="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="100 MB"/>
</Policies>
</RollingFile>

<RollingFile name="RollingFileInfo" fileName="/home/app-logs/xxx/info.log"
filePattern="/home/app-logs/xxx/$${date:yyyy-MM}/info-%d{yyyy-MM-dd}-%i.log">
<Filters>
<ThresholdFilter level="INFO"/>
<ThresholdFilter level="WARN" onMatch="DENY" onMismatch="NEUTRAL"/>
</Filters>
<PatternLayout pattern="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="100 MB"/>
</Policies>
</RollingFile>

<RollingFile name="RollingFileWarn" fileName="/home/app-logs/xxx/warn.log"
filePattern="/home/app-logs/xxx/$${date:yyyy-MM}/warn-%d{yyyy-MM-dd}-%i.log">
<Filters>
<ThresholdFilter level="WARN"/>
<ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="NEUTRAL"/>
</Filters>
<PatternLayout pattern="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="100 MB"/>
</Policies>
</RollingFile>

<RollingFile name="RollingFileError" fileName="/home/app-logs/xxx/error.log"
filePattern="/home/app-logs/xxx/$${date:yyyy-MM}/error-%d{yyyy-MM-dd}-%i.log">
<ThresholdFilter level="ERROR"/>
<PatternLayout pattern="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="100 MB"/>
</Policies>
</RollingFile>

<RollingFile name="RollingFileCrowd" fileName="/home/app-logs/xxx/business-logs/business.log"
filePattern="/home/app-logs/xxx/business-logs/$${date:yyyy-MM}/business-%d{yyyy-MM-dd}-%i.log">
<Filters>
<ThresholdFilter level="DEBUG"/>
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="ACCEPT"/>
<ThresholdFilter level="WARN" onMatch="ACCEPT" onMismatch="ACCEPT"/>
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="ACCEPT"/>
</Filters>
<PatternLayout pattern="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="100 MB"/>
</Policies>
</RollingFile>

<RollingFile name="RequestLogFile" fileName="/home/app-logs/xxx/business-logs/request.log"
filePattern="/home/app-logs/xxx/business-logs/$${date:yyyy-MM}/request-%d{yyyy-MM-dd}-%i.log">
<Filters>
<ThresholdFilter level="DEBUG"/>
<ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="ACCEPT"/>
<ThresholdFilter level="WARN" onMatch="ACCEPT" onMismatch="ACCEPT"/>
<ThresholdFilter level="ERROR" onMatch="ACCEPT" onMismatch="ACCEPT"/>
</Filters>
<PatternLayout pattern="[%d{HH:mm:ss:SSS}] [%p] - %l - %m%n"/>
<Policies>
<TimeBasedTriggeringPolicy/>
<SizeBasedTriggeringPolicy size="100 MB"/>
</Policies>
</RollingFile>

</appenders>

<loggers>
<!--过滤掉spring和hibernate的一些无用的debug信息-->
<Logger name="org.elasticsearch.transport.netty4" level="INFO"/>
<Logger name="businessLog">
<appender-ref ref="RollingFileCrowd"/>
</Logger>
<Logger name="request">
<appender-ref ref="RequestLogFile"/>
</Logger>
<ROOT level="debug">
<appender-ref ref="Console"/>
<appender-ref ref="RollingFileALL"/>
<appender-ref ref="RollingFileInfo"/>
<appender-ref ref="RollingFileWarn"/>
<appender-ref ref="RollingFileError"/>
<!-- <appender-ref ref="RollingFileCrowd"/> -->
</ROOT>
</loggers>

</configuration>
posted on 2020-02-01 20:53  卖小女孩的小男孩  阅读(175)  评论(0)    收藏  举报