How to configure logback to skip logging messages

2019-03-17 23:44发布

问题:

How do I configure logback not to log messages from loggers in package org.package and it's subpackages unless their level is WARN or ERROR?

回答1:

And why isn't the following configuration not working for you?

<configuration>
    <logger name="org.package" level="WARN"/>

    <root level="ALL">
        <appender class="ch.qos.logback.core.ConsoleAppender">
            <encoder>
                <pattern>%d{ISO8601} | %-5level | %thread | %logger{1} | %m%n</pattern>
            </encoder>
        </appender>
    </root>
</configuration>


回答2:

log.getLoggerContext().getLogger("package.name").setLevel(Level.WARN);