1 <?xml version="1.0" encoding="UTF-8"?> 2 <configuration scan="true" scanPeriod="60 seconds"> 3 <!-- 彩色日志 --> 4 <!-- 彩色日志依赖的渲染类 --> 5 <conversionRule conversionWord="clr" converterClass="org.springframework.boot.logging.logback.ColorConverter"/> 6 <conversionRule conversionWord="wex" 7 converterClass="org.springframework.boot.logging.logback.WhitespaceThrowableProxyConverter"/> 8 <conversionRule conversionWord="wEx" 9 converterClass="org.springframework.boot.logging.logback.ExtendedWhitespaceThrowableProxyConverter"/> 10 <!-- 彩色日志格式 --> 11 <property name="CONSOLE_LOG_PATTERN" 12 value="${CONSOLE_LOG_PATTERN:-%clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}}"/> 13 14 <contextName>logback</contextName> 15 16 <!--定义日志文件的存储地址 --> 17 <property name="LOG_HOME" value="logs"/> 18 19 <appender name="Console" class="ch.qos.logback.core.ConsoleAppender"> 20 <!--此日志appender是为开发使用,只配置最底级别,控制台输出的日志级别是大于或等于此级别的日志信息--> 21 <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> 22 <level>DEBUG</level> 23 </filter> 24 <!--encoder 默认配置为PatternLayoutEncoder--> 25 <encoder> 26 <pattern>${CONSOLE_LOG_PATTERN}</pattern> 27 <charset>utf-8</charset> 28 </encoder> 29 </appender> 30 31 <appender name="RollingFile" 32 class="ch.qos.logback.core.rolling.RollingFileAppender"> 33 <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> 34 <level>DEBUG</level> 35 </filter> 36 <!-- 可让每天产生一个日志文件,最多 180 个,自动回滚 --> 37 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 38 <fileNamePattern>${LOG_HOME}/%d{yyyy-MM,aux}/knowledgebase-%d{yyyy-MM-dd}.log 39 </fileNamePattern> 40 <!-- keep 15 days' worth of history capped at 10GB total size --> 41 <maxHistory>15</maxHistory> 42 <totalSizeCap>10GB</totalSizeCap> 43 </rollingPolicy> 44 <!-- 日志文件的格式 --> 45 <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> 46 <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level --- [%file:%line][%thread] - %msg%n</pattern> 47 <charset>utf-8</charset> 48 </encoder> 49 </appender> 50 51 <appender name="AsyncRollingFile" class="ch.qos.logback.classic.AsyncAppender"> 52 <appender-ref ref="RollingFile"/> 53 <includeCallerData>true</includeCallerData> 54 </appender> 55 56 <!-- 输出到控制台和文件,可定义更多的 Appender --> 57 <root level="INFO"> 58 <appender-ref ref="Console"/> 59 <appender-ref ref="AsyncRollingFile"/> 60 </root> 61 62 <!-- 下面配置一些第三方包的日志过滤级别,用于避免刷屏 --> 63 <logger name="org.mybatis" level="INFO"/> 64 <logger name="org.springframework" level="WARN"/> 65 <logger name="org.apache" level="WARN"/> 66 <!-- <!–如果需要打印SQL,可以把下面的级别设置为DEBUG –>--> 67 <!-- <logger name="com.heeexy.example.dao" level="DEBUG"/>--> 68 69 </configuration>