How do I turn logging off using log4j?

2020-02-25 22:44发布

I am using a third-party library which has a log4j.xml configuration - what's the best way to turn off the logging?

5条回答
Explosion°爆炸
2楼-- · 2020-02-25 23:16

Or directly from code:

Logger.getRootLogger().removeAllAppenders();
查看更多
Anthone
3楼-- · 2020-02-25 23:18

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>
查看更多
乱世女痞
4楼-- · 2020-02-25 23:24

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.

查看更多
男人必须洒脱
5楼-- · 2020-02-25 23:26

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

查看更多
够拽才男人
6楼-- · 2020-02-25 23:42

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.

查看更多
登录 后发表回答