如何使用logBack.xml在spring中为specefic类设置loglevel?

时间:2017-04-20 16:37:42

标签: spring logging logback

我试图不在类com.data.march.ClientUtils.中记录调试消息。我认为我可以将logBack.xml中该类的loglevel更改为Error。

以下是我的代码的一部分:

<appender name="dailyRollingFileAppender"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <File>c:/Logs/logato.log</File>
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <!-- daily rollover -->
        <FileNamePattern>c:/Logato/Data/Logs/Logato.%d{yyyy-MM-dd}.log
        </FileNamePattern>

        <!-- keep 30 days' worth of history -->
        <maxHistory>30</maxHistory>
    </rollingPolicy>

    <encoder>
        <Pattern>%d{HH:mm:ss.SSS} %-5level [%thread] %logger{35} - %msg %n
        </Pattern>
    </encoder>
</appender>
<appender name="minuteRollingFileAppender"
    class="ch.qos.logback.core.rolling.RollingFileAppender">
    <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
        <!-- rollover every minute -->
        <FileNamePattern>c:/Data/Logs/minutes/Logato-minute.%d{yyyy-MM-dd_HH-mm}.log
        </FileNamePattern>

        <!-- keep 30 minutes' worth of history -->
        <maxHistory>30</maxHistory>
    </rollingPolicy>
    <encoder>
        <Pattern>%-4relative %-5level [%thread] %logger{35} - %msg %n
        </Pattern>
    </encoder>
</appender>
<logger name="org" additivity="false">
    <level value="INFO" />
    <appender-ref ref="dailyRollingFileAppender" />
    <appender-ref ref="consoleAppender" />
</logger>
<logger name="com.data" additivity="false">
    <level value="DEBUG" />
    <appender-ref ref="dailyRollingFileAppender" />
    <appender-ref ref="consoleAppender" />
</logger>
<appender name="consoleAppender" class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
        <Pattern>.%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg %n
        </Pattern>
    </encoder>
    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
        <level>TRACE</level>
    </filter>
</appender>
<logger name="org" additivity="false">
    <level value="INFO" />
    <appender-ref ref="dailyRollingFileAppender" />
</logger>
<logger
    name="com.data.march.ClientUtils"
    additivity="false">
    <level value="ERROR" />
</logger>
<root>
    <level value="DEBUG" />
    <appender-ref ref="consoleAppender" />
</root>

但我的尝试失败了。你知道吗?

1 个答案:

答案 0 :(得分:5)

尝试添加此内容:

<logger name="com.data.march.ClientUtils" level="error"/>