logbak配置级别的时候出现级别不能控制的其他日志

newsomeone 发布于 2018/03/29 10:38
阅读 942
收藏 2
<root level="DEBUG">
    <appender-ref ref="TRACE_FILE" />
    <appender-ref ref="DEBUG_FILE" />
    <appender-ref ref="INFO_FILE" />
    <appender-ref ref="WARN_FILE" />
    <appender-ref ref="ERROR_FILE" />
    <appender-ref ref="STDOUT" />
</root>

root的级别设置为的debug

然后在logger节点又定义了

<logger name="com.alibaba.druid" level="ERROR"/>

其他日志都是正常的,就是这个druid的日志级别不能控制,除非把root级别调到DEBUG之上才不会显示。

druid显示的日志:

后面发现这个日志是在

com.alibaba.druid.filter.logging.Log4JFilter

打印出来的,用的是log4j,不知道这个有没有关系。

找资料发现还有一种可能情况,logbak和druid的日志相关配置类的加载先后顺序导致的,

需要在web.xml中配置加载监听器的顺序。可是我用的是spring-boot 现在里面没有配置webapp的模块。有没有人遇到过这样的情况,弄了好久了。。。。

 

下面贴一下我的logbak-spring.xml

<?xml version="1.0" encoding="UTF-8"?>
<configuration scan="true" scanPeriod="60 seconds" debug="false">
    <contextName>logback</contextName>
    <property name="PATH" value="logs"/>
    <!--console-->
    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
        <withJansi>true</withJansi>
        <encoder>
            <charset>UTF-8</charset>
            <pattern>%d{yyyy-MM-dd HH🇲🇲ss.SSS} %highlight(%-5level) %magenta(${PID:-}) --- %green([%15.15thread]) %cyan(%40.40logger) #%-5.5L : %black(%msg%n)</pattern>
        </encoder>
    </appender>
    <!--trace-->
    <appender name="TRACE_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${PATH}/trace.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${PATH}/trace.%d{yyyy-MM-dd}.log</FileNamePattern>
            <maxHistory>60</maxHistory>
            <totalSizeCap>1GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>[%d{yyyy-MM-dd HH🇲🇲ss.SSS}] [%-5level] [%logger:%line]--%mdc{client} %msg%n</pattern>
        </encoder>
    </appender>
    <!--info-->
    <appender name="INFO_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${PATH}/info.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${PATH}/info.%d{yyyy-MM-dd}.log</FileNamePattern>
            <maxHistory>60</maxHistory>
            <totalSizeCap>1GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>[%d{yyyy-MM-dd HH🇲🇲ss.SSS}] [%-5level] [%logger:%line]--%mdc{client} %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="DEBUG_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${PATH}/debug.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${PATH}/debug.%d{yyyy-MM-dd}.log</FileNamePattern>
            <maxHistory>60</maxHistory>
            <totalSizeCap>1GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>[%d{yyyy-MM-dd HH🇲🇲ss.SSS}] [%-5level] [%logger:%line]--%mdc{client} %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="WARN_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${PATH}/warn.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${PATH}/warn.%d{yyyy-MM-dd}.log</FileNamePattern>
            <maxHistory>60</maxHistory>
            <totalSizeCap>1GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>[%d{yyyy-MM-dd HH🇲🇲ss.SSS}] [%-5level] [%logger:%line]--%mdc{client} %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="ERROR_FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <file>${PATH}/error.log</file>
        <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
            <FileNamePattern>${PATH}/error.%d{yyyy-MM-dd}.log</FileNamePattern>
            <maxHistory>60</maxHistory>
            <totalSizeCap>1GB</totalSizeCap>
        </rollingPolicy>
        <encoder>
            <pattern>[%date{yyyy-MM-dd HH🇲🇲ss}] [%-5level] [%logger:%line]--%mdc{client} %msg%n</pattern>
        </encoder>
        <filter class="ch.qos.logback.classic.filter.LevelFilter">
            <level>ERROR</level>
            <onMatch>ACCEPT</onMatch>
            <onMismatch>DENY</onMismatch>
        </filter>
    </appender>

    <root level="DEBUG">
        <appender-ref ref="TRACE_FILE" />
        <appender-ref ref="DEBUG_FILE" />
        <appender-ref ref="INFO_FILE" />
        <appender-ref ref="WARN_FILE" />
        <appender-ref ref="ERROR_FILE" />
        <appender-ref ref="STDOUT" />
    </root>



    <!--logger 模块 -->

    <!--开发环境需要debug级别的日志,生产环境不需要-->
    <logger name="com.ytt" level="DEBUG" additivity="false">
        <appender-ref ref="STDOUT"/>
    </logger>

    <!--开发环境和生产环境都不需要的日志 级别设置为INFO-->
    <logger name="ch.qos.logback" level="INFO" />
    <logger name="org.springframework" level="INFO" />
    <logger name="com.ibeetl" level="INFO" />
    <logger name="org.mybatis" level="INFO"/>
    <logger name="org.apache.ibatis" level="INFO"/>
    <logger name="org.apache.shiro" level="INFO"/>
    <logger name="java.sql.Connection" level="INFO" />
    <logger name="java.sql.Statement" level="INFO" />
    <logger name="java.sql.PreparedStatement" level="INFO" />
    <logger name="org.hibernate" level="INFO"/>
    <logger name="com.alibaba.druid" level="ERROR"/>
</configuration>
加载中
0
蚂蚁-Declan
蚂蚁-Declan

应该是要在logger中配置appender-ref吧,然后logger中还需要配置additivity="false"吧

 

OSCHINA
登录后可查看更多优质内容
返回顶部
顶部