背景:
前两天在看线上问题的时候,突然发现在logback.xml文件注释了debug级别的日志输出,导致info,warn,error级别的日志都不输出了。
logback.xml配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<property name="logPath" value="E:/workspace/log/user-log1/" />
<appender name="debug" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${logPath}server-debug.log</File>
<encoder>
<pattern>%d{yyyy-MM-dd.HH:mm:ss} [%5p] %c{50} %3L %M %m%n</pattern>
</encoder>
<!-- 只输出debug级别的日志 -->
<filter class = "ch.qos.logback.classic.filter.LevelFilter">
<level>DEBUG</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${logPath}server-debug.log.%d{yyyy-MM-dd}</fileNamePattern>
<maxHistory>2</maxHistory>
</rollingPolicy>
</appender>
<appender name="info" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${logPath}/server-info.log</File>
<encoder>
<pattern>%d{yyyy-MM-dd.HH:mm:ss} [%5p] %c{50} %3L %M %m%n</pattern>
</encoder>
<filter class = "ch.qos.logback.classic.filter.LevelFilter">
<level>INFO</level>
<onMatch>ACCEPT</onMatch>
<onMismatch>DENY</onMismatch>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${logPath}/server-info.log.%d{yyyy-MM-dd}</fileNamePattern>
<maxHistory>2</maxHistory>
</rollingPolicy>
</appender>
<appender name="warn" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${logPath}/server-warn.log</File>
<encoder>
<pattern>%d{yyyy-MM-dd.HH:mm:ss} [%5p] %c{50} %3L %M %m%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>warn</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${logPath}/server-warn.log.%d{yyyy-MM-dd}</fileNamePattern>
</rollingPolicy>
</appender>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- 日志输出编码 -->
<Encoding>UTF-8</Encoding>
<layout class="ch.qos.logback.classic.PatternLayout">
<!--格式化输出:%d表示日期,%thread表示线程名,%-5level:级别从左显示5个字符宽度%msg:日志消息,%n是换行符-->
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n
</pattern>
</layout>
</appender>
<appender name="debug1" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>${logPath}debug1.log</File>
<Encoding>UTF-8</Encoding>
<encoder>
<pattern>%d{yyyy-MM-dd.HH:mm:ss} [%5p] %c{50} %3L %M %m%n</pattern>
</encoder>
<!-- 只输出level级别以上的日志 -->
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>debug</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<fileNamePattern>${logPath}debug1.log.%d{yyyy-MM-dd}</fileNamePattern>
</rollingPolicy>
</appender>
<logger name="com.baidu.soa.crm.user.Main" level="DEBUG" additivity="false">
<appender-ref ref="debug1"/>
</logger>
<logger name="com.baidu.soa.crm.user" additivity="false">
<appender-ref ref="debug" />
<appender-ref ref="info"/>
<appender-ref ref="warn"/>
<appender-ref ref="STDOUT"/>
</logger>
<root level="debug"></root>
</configuration>
注意其中
<logger name="com.baidu.soa.crm.user.Main" level="DEBUG" additivity="false">
<appender-ref ref="debug1"/>
</logger>
这个logger中配置的name已经是包具体的类名,而且additivity=false,表明日志大于这个级别的级别将不向上继续抛出。
所以导致
<logger name="com.baidu.soa.crm.user" additivity="false">
<appender-ref ref="debug" />
<appender-ref ref="info"/>
<appender-ref ref="warn"/>
<appender-ref ref="STDOUT"/>
</logger>
输出不了大于debug级别的日志类型。如果在com.baidu.soa.crm.user包其他的类型则能够正常的输出debug级别以上的日志。