Java 如何使用 log4j 关闭注销?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1244487/
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 do I turn logging off using log4j?
提问by Corehpf
I am using a third-party library which has a log4j.xml configuration - what's the best way to turn off the logging?
我正在使用具有 log4j.xml 配置的第三方库 - 关闭日志记录的最佳方法是什么?
采纳答案by John McG
I think all that is required is to set the threshold parameter to OFF
我认为所需要做的就是将阈值参数设置为 OFF
<log4j:configuration threshold="OFF">
<root>
<priority value ="off" />
<appender-ref ref="console" />
<appender-ref ref="rolling-file" />
</root>
</log4j:configuration>
回答by Grzegorz Gierlik
Depends on configuration. Try something like:
取决于配置。尝试类似:
<log4j:configuration>
<root>
<priority value ="off" />
<appender-ref ref="console" />
<appender-ref ref="rolling-file" />
</root>
</log4j:configuration>
Check Log4jXmlFormatfor more details.
检查Log4jXmlFormat以获取更多详细信息。
回答by Justin
You could also try setting the logging level to "Severe" if you only want to log game-breaking events.
如果您只想记录破坏游戏的事件,您也可以尝试将日志记录级别设置为“严重”。
回答by Karl
Or directly from code:
或者直接从代码:
Logger.getRootLogger().removeAllAppenders();
回答by user1433852
With log4j.xml the minimal solution looks like this:
使用 log4j.xml 的最小解决方案如下所示:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration threshold="off">
</log4j:configuration>
Note that in threshold="off"
, "off" must be in lower case.
请注意,在 中threshold="off"
,“off”必须为小写。