java 如何配置 logback 以跳过 org.package.* 中所有级别低于 WARN 的日志消息?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5924089/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to configure logback to skip logging messages from org.package.* with all levels below WARN?
提问by Vladislav Rastrusny
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?
如何配置 logback 不记录来自 org.package 包及其子包中的记录器的消息,除非它们的级别是 WARN 或 ERROR?
回答by Tomasz Nurkiewicz
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>
回答by thouliha
log.getLoggerContext().getLogger("package.name").setLevel(Level.WARN);
log.getLoggerContext().getLogger("package.name").setLevel(Level.WARN);