<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds">
<!-- 控制台设置 -->
<contextName>logback</contextName>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<!-- INFO -->
<appender name="infoAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 文件路径 ,注意LOG_PATH是默认值,
它的配置对应application.properties里的logging.path值-->
<file>${LOG_PATH}/info/info.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 文件名称 -->
<fileNamePattern>${LOG_PATH}/info/info-%d{yyyy-MM-dd}.log
</fileNamePattern>
<!-- 文件最大保存历史数量 -->
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- DEBUG -->
<appender name="debugAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 文件路径 ,注意LOG_PATH是默认值,
它的配置对应application.properties里的logging.path值-->
<file>${LOG_PATH}/debug/debug.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 文件名称 -->
<fileNamePattern>${LOG_PATH}/debug/debug-%d{yyyy-MM-dd}.log</fileNamePattern>
<!-- 文件最大保存历史数量 -->
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- WARN -->
<appender name="warnAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 文件路径 ,注意LOG_PATH是默认值,
它的配置对应application.properties里的logging.path值-->
<file>${LOG_PATH}/warn/warn.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 文件名称 -->
<fileNamePattern>${LOG_PATH}/warn/warn-%d{yyyy-MM-dd}.log
</fileNamePattern>
<!-- 文件最大保存历史数量 -->
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>WARN</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<!-- ERROR -->
<appender name="errorAppender" class="ch.qos.logback.core.rolling.RollingFileAppender">
<!-- 文件路径 ,注意LOG_PATH是默认值,
它的配置对应application.properties里的logging.path值-->
<file>${LOG_PATH}/error/error.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- 文件名称 -->
<fileNamePattern>${LOG_PATH}/error/error-%d{yyyy-MM-dd}.log
</fileNamePattern>
<!-- 文件最大保存历史数量 -->
<MaxHistory>30</MaxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
</appender>
<logger name="org.springframework" additivity="false">
<level value="ERROR" />
<appender-ref ref="STDOUT" />
<appender-ref ref="errorAppender" />
</logger>
<!-- 由于启动的时候,以下两个包下打印debug级别日志很多 ,所以调到ERROR-->
<logger name="org.apache.tomcat.util" additivity="false">
<level value="ERROR"/>
<appender-ref ref="STDOUT"/>
<appender-ref ref="errorAppender"/>
</logger>
<!-- 默认spring boot导入hibernate很多的依赖包,启动的时候,会有hibernate相关的内容,直接去除 -->
<logger name="org.hibernate.validator" additivity="false">
<level value="ERROR"/>
<appender-ref ref="STDOUT"/>
<appender-ref ref="errorAppender"/>
</logger>
<root level="DEBUG">
<appender-ref ref="STDOUT"/>
<appender-ref ref="infoAppender"/>
<appender-ref ref="debugAppender"/>
<appender-ref ref="warnAppender"/>
<appender-ref ref="errorAppender"/>
</root>
</configuration>
网友评论