Spring boot 日志系统 logback-spring.xml配置
依赖包,但是像spring-web里面已经集成不需要额外添加
<!--全局排除spring-boot-starter-logging内的所有依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
logback-spring.xml 文件配置
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<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.slf4j" level="INFO"/>
<logger name="springfox" level="INFO"/>
<logger name="io.swagger" level="INFO"/>
<logger name="com.gt.lsv" level="INFO"/>
<logger name="org.springframework" 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>
application.yml 配置日志输出路径
logging:
file:
path: /logs/lsv