|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
|
<configuration>
|
|
|
<include resource="org/springframework/boot/logging/logback/base.xml"/>
|
|
|
|
|
|
<!--定义日志文件的存储地址-->
|
|
|
<property name="LOG_HOME" value="logs"/>
|
|
|
|
|
|
|
|
|
<!-- %m输出的信息,%p日志级别,%t线程名,%d日期,%c类的全名,,,, -->
|
|
|
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
|
|
<encoder>
|
|
|
<!--<pattern>%d %p (%file:%line\)- %m%n</pattern>-->
|
|
|
<!--格式化输出:%d:表示日期 %thread:表示线程名 %-5level:级别从左显示5个字符宽度 %msg:日志消息 %n:是换行符-->
|
|
|
<pattern>1-%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger - %msg%n</pattern>
|
|
|
<charset>UTF-8</charset>
|
|
|
</encoder>
|
|
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
|
<level>ERROR</level>
|
|
|
<onMatch>ACCEPT</onMatch>
|
|
|
<onMismatch>DENY</onMismatch>
|
|
|
</filter>
|
|
|
</appender>
|
|
|
|
|
|
|
|
|
<!-- 按照每天生成日志文件 -->
|
|
|
<appender name="ACCESS" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
|
<!--日志文件输出的文件名-->
|
|
|
<FileNamePattern>${LOG_HOME}/access_%d{yyyy-MM-dd}.%i.log</FileNamePattern>
|
|
|
<!--日志文件保留天数-->
|
|
|
<MaxHistory>30</MaxHistory>
|
|
|
<!--日志文件最大的大小-->
|
|
|
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
|
|
<maxFileSize>10MB</maxFileSize>
|
|
|
</timeBasedFileNamingAndTriggeringPolicy>
|
|
|
</rollingPolicy>
|
|
|
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
|
|
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
|
|
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
|
|
<charset>UTF-8</charset>
|
|
|
</encoder>
|
|
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
|
<level>INFO</level>
|
|
|
<onMatch>ACCEPT</onMatch>
|
|
|
<onMismatch>DENY</onMismatch>
|
|
|
</filter>
|
|
|
</appender>
|
|
|
|
|
|
<appender name="ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">
|
|
|
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
|
|
|
<FileNamePattern>${LOG_HOME}/errors_%d{yyyy-MM-dd}.%i.log</FileNamePattern>
|
|
|
<MaxHistory>30</MaxHistory>
|
|
|
<timeBasedFileNamingAndTriggeringPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedFNATP">
|
|
|
<maxFileSize>10MB</maxFileSize>
|
|
|
</timeBasedFileNamingAndTriggeringPolicy>
|
|
|
</rollingPolicy>
|
|
|
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
|
|
|
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>
|
|
|
<charset>UTF-8</charset>
|
|
|
</encoder>
|
|
|
<filter class="ch.qos.logback.classic.filter.LevelFilter">
|
|
|
<level>ERROR</level>
|
|
|
<onMatch>ACCEPT</onMatch>
|
|
|
<onMismatch>DENY</onMismatch>
|
|
|
</filter>
|
|
|
</appender>
|
|
|
|
|
|
|
|
|
<logger name="org.springframework.web" level="ERROR"/>
|
|
|
<logger name="org.springboot.sample" level="ERROR"/>
|
|
|
<logger name="com.yuxue" level="DEBUG"/>
|
|
|
|
|
|
<!-- 开发、测试环境 -->
|
|
|
<springProfile name="dev,test">
|
|
|
<root level="DEBUG">
|
|
|
<appender-ref ref="ACCESS" />
|
|
|
</root>
|
|
|
</springProfile>
|
|
|
|
|
|
<!-- 所有环境都要记录错误日志 -->
|
|
|
<root level="ERROR">
|
|
|
<appender-ref ref="ERROR"/>
|
|
|
</root>
|
|
|
|
|
|
|
|
|
</configuration> |