How do I turn logging off using log4j?

女生的网名这么多〃 提交于 2019-11-30 07:02:41

I think all that is required is to set the threshold parameter to OFF

<log4j:configuration threshold="OFF">
    <root>
        <priority value ="off" />
        <appender-ref ref="console" />
        <appender-ref ref="rolling-file" />
    </root>
</log4j:configuration>

Or directly from code:

Logger.getRootLogger().removeAllAppenders();

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 Log4jXmlFormat for more details.

You could also try setting the logging level to "Severe" if you only want to log game-breaking events.

With log4j.xml the minimal solution looks like this:

<?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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!