如何使用 log4j 关闭日志记录?

发布于 2024-07-29 23:40:43 字数 50 浏览 7 评论 0原文

我正在使用具有 log4j.xml 配置的第三方库 - 关闭日志记录的最佳方法是什么?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

想你只要分分秒秒 2024-08-05 23:40:43

我认为所需要做的就是将阈值参数设置为 OFF

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

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>
彩虹直至黑白 2024-08-05 23:40:43

或者直接从代码:

Logger.getRootLogger().removeAllAppenders();

Or directly from code:

Logger.getRootLogger().removeAllAppenders();
不疑不惑不回忆 2024-08-05 23:40:43

取决于配置。 尝试类似的操作:

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

检查 Log4jXmlFormat 了解更多详细信息。

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.

南街女流氓 2024-08-05 23:40:43

对于 log4j.xml,最小解决方案如下所示:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration threshold="off">
</log4j:configuration>

请注意,在 threshold="off" 中,“off”必须为小写。

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.

好久不见√ 2024-08-05 23:40:43

如果您只想记录破坏游戏的事件,您也可以尝试将日志记录级别设置为“严重”。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文