Java 如何在运行时更改单个记录器的日志级别?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18102898/
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 can I change log level of single logger in runtime?
提问by fedor.belov
I wanna read spring
property and based on this property change log level for some packages (not for root logger). How can I implement it using logback?
我想读取spring
属性并基于此属性更改某些包的日志级别(而不是根记录器)。如何使用 logback 实现它?
采纳答案by GreyFairer
See top related question: SLF4J - Logback: How to configure loggers in runtime?
请参阅最相关的问题:SLF4J - Logback: How to configure loggers in runtime?
More specific ((ch.qos.logback.classic.Logger)LoggerFactory.getLogger("abc.xyz")) .setLevel(Level.XXX)
should do the trick.
更具体的((ch.qos.logback.classic.Logger)LoggerFactory.getLogger("abc.xyz")) .setLevel(Level.XXX)
应该可以解决问题。
I'm not sure what your use case is, but I prefer to use the JMX interface: http://logback.qos.ch/manual/jmxConfig.html.
我不确定您的用例是什么,但我更喜欢使用 JMX 接口:http: //logback.qos.ch/manual/jmxConfig.html。