Logback / Weblogic如何设置不同的日志级别?

时间:2013-08-26 14:07:55

标签: logback

我使用的是Weblogic 10.3.6,我无法控制2个不同的appender(com.my& root)的不同日志级别 使用给定的logback.xml,我期望只有文件appender的TRACE级别和weblogic终端下的任何内容。问题是我在两者上得到相同的输出。

<?xml version="1.0" encoding="UTF-8"?>

<!-- For assistance related to logback-translator or configuration  -->
<!-- files in general, please contact the logback user mailing list -->
<!-- at http://www.qos.ch/mailman/listinfo/logback-user             -->
<!--                                                                -->
<!-- For professional support please see                            -->
<!--    http://www.qos.ch/shop/products/professionalSupport         -->
<!--                                                                -->
<configuration>
    <contextName>myContx</contextName>
    <jmxConfigurator />
    <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">
        <!--See also http://logback.qos.ch/manual/appenders.html#RollingFileAppender-->
        <File>/var/log/a.log</File>
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} %5p %c{1}:%L - %m%n</pattern>
        </encoder>
        <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
            <maxIndex>1</maxIndex>
            <FileNamePattern>/var/log/a.log.%i</FileNamePattern>
        </rollingPolicy>
        <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
            <MaxFileSize>1MB</MaxFileSize>
        </triggeringPolicy>
    </appender>
    <appender name="out"
              class="ch.qos.logback.core.ConsoleAppender">
        <layout class="ch.qos.logback.classic.PatternLayout">
            <pattern>%-4relative [%thread] %-5level %class - %msg%n</pattern>
        </layout>
    </appender>


    <logger name="com.my" level="trace">
        <appender-ref ref="file" />
    </logger>
    <root level="off">
        <appender-ref ref="out" />
    </root>
</configuration>

1 个答案:

答案 0 :(得分:2)

我想说设置可加性标志可以帮助你:

<logger name="com.my" level="trace" additivity="false">
    <appender-ref ref="file" />
</logger>

请参阅http://logback.qos.ch/manual/configuration.html#overrridingCumulativity