1 <?xml version="1.0" encoding="UTF-8" ?> 2 <configuration> 3 4 <appender name="consoleApp" class="ch.qos.logback.core.ConsoleAppender"> 5 <layout class="ch.qos.logback.classic.PatternLayout"> 6 <pattern> 7 %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level[%thread]%logger{56}.%method:%L -%msg%n 8 </pattern> 9 <pattern> 10 %red(%d{yyyy-MM-dd HH:mm:ss.SSS}) %green([%thread]) %highlight(%-5level) %boldMagenta(%logger{10}) - 11 %cyan(%msg%n) 12 </pattern> 13 </layout> 14 </appender> 15 16 <appender name="fileInfoApp" class="ch.qos.logback.core.rolling.RollingFileAppender"> 17 <filter class="ch.qos.logback.classic.filter.LevelFilter"> 18 <level>ERROR</level> 19 <onMatch>DENY</onMatch> 20 <onMismatch>ACCEPT</onMismatch> 21 </filter> 22 <encoder> 23 <pattern> 24 %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level[%thread]%logger{56}.%method:%L -%msg%n 25 </pattern> 26 </encoder> 27 <!-- 滚动策略 --> 28 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 29 <!-- 路径 --> 30 <fileNamePattern>D:/logs/test-log/app.info.%d.log</fileNamePattern> 31 </rollingPolicy> 32 </appender> 33 34 <appender name="fileErrorApp" class="ch.qos.logback.core.rolling.RollingFileAppender"> 35 <filter class="ch.qos.logback.classic.filter.ThresholdFilter"> 36 <level>ERROR</level> 37 </filter> 38 <encoder> 39 <pattern> 40 %date{yyyy-MM-dd HH:mm:ss.SSS} %-5level[%thread]%logger{56}.%method:%L -%msg%n 41 </pattern> 42 </encoder> 43 44 <!-- 设置滚动策略 --> 45 <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> 46 <!-- 路径 --> 47 <fileNamePattern>D:/logs/test-log/app.err.%d.log</fileNamePattern> 48 49 <!-- 控制保留的归档文件的最大数量,超出数量就删除旧文件,假设设置每个月滚动, 50 且<maxHistory> 是1,则只保存最近1个月的文件,删除之前的旧文件 --> 51 <MaxHistory>1</MaxHistory> 52 53 </rollingPolicy> 54 </appender> 55 <root level="info"> 56 <appender-ref ref="consoleApp"/> 57 <appender-ref ref="fileInfoApp"/> 58 <appender-ref ref="fileErrorApp"/> 59 </root> 60 </configuration>