<?xml version="1.0" encoding="UTF-8"?> <!--日志级别以及优先级排序: OFF > FATAL > ERROR > WARN > INFO > DEBUG > TRACE > ALL --> <!--Configuration后面的status,这个用于设置log4j2自身内部的信息输出,可以不设置,当设置成trace时,你会看到log4j2内部各种详细输出--> <!--monitorInterval:Log4j能够自动检测修改配置 文件和重新配置本身,设置间隔秒数--> <!--设置log4j2的自身log级别为warn--> <configuration status="DEBUG" monitorInterval="30"> <properties> <property name="filePath" value="logs" /> </properties> <!--先定义所有的appender--> <appenders> <!--这个输出控制台的配置--> <console name="Console" target="SYSTEM_OUT"> <!--输出日志的格式--> <PatternLayout pattern="%date [%thread] %-5level %class.%method\(%line\) - %msg%n"/> </console> <!-- 这个会打印出所有的info及以上级别的信息,按天切分,自动存入按年份-月份建立的文件夹下面--> <RollingFile name="RollingFileInfo" fileName="${filePath}/info.log" filePattern="${filePath}/$${date:yyyy-MM}/info-%d{yyyy-MM-dd}.log"> <Filters> <!--控制台只输出level及以上级别的信息(onMatch),其他的直接拒绝(onMismatch)--> <ThresholdFilter level="INFO" onMatch="ACCEPT" onMismatch="DENY"/> <ThresholdFilter level="WARN" onMatch="DENY" onMismatch="NEUTRAL"/> </Filters> <PatternLayout pattern="%date [%thread] %-5level %class.%method\(%line\) - %msg%n"/> <Policies> <TimeBasedTriggeringPolicy modulate="true" interval="1"/> </Policies> </RollingFile> <RollingFile name="RollingFileWarn" fileName="${filePath}/warn.log" filePattern="${filePath}/$${date:yyyy-MM}/warn-%d{yyyy-MM-dd}.log"> <Filters> <ThresholdFilter level="WARN" onMatch="ACCEPT" onMismatch="DENY"/> <ThresholdFilter level="ERROR" onMatch="DENY" onMismatch="NEUTRAL"/> </Filters> <PatternLayout pattern="%date [%thread] %-5level %class.%method\(%line\) - %msg%n"/> <Policies> <TimeBasedTriggeringPolicy modulate="true" interval="1"/> </Policies> </RollingFile> <RollingFile name="RollingFileError" fileName="${filePath}/error.log" filePattern="${filePath}/$${date:yyyy-MM}/error-%d{yyyy-MM-dd}.log"> <ThresholdFilter level="ERROR"/> <PatternLayout pattern="%date [%thread] %-5level %class.%method\(%line\) - %msg%n"/> <Policies> <TimeBasedTriggeringPolicy modulate="true" interval="1"/> </Policies> </RollingFile> </appenders> <!--然后定义logger,只有定义了logger并引入的appender,appender才会生效--> <loggers> <!--过滤掉spring和mybatis的一些无用的debug信息--> <logger name="org.springframework" level="ERROR" /> <logger name="org.mybatis" level="DEBUG" /> <!-- 异步输出 --> <asyncRoot level="DEBUG" includeLocation="true"> <appender-ref ref="Console"/> <appender-ref ref="RollingFileInfo"/> <appender-ref ref="RollingFileWarn"/> <appender-ref ref="RollingFileError"/> </asyncRoot> </loggers> </configuration>
转载于:https://my.oschina.net/TonyTaotao/blog/2986982