从第3方jar抑制Java util日志记录 [英] Suppress java util logging from 3rd party jar

查看:93
本文介绍了从第3方jar抑制Java util日志记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Eclipse控制台中的第3方jar中获取了大量的信息日志消息.打开罐子,我看到它使用了java.util.logging.我想将其jar的输出级别设置为警告".

I am getting tons of info log messages from a 3rd party jar in my eclipse console. Cracking open the jar I see that it uses java.util.logging. I would like to set the output level for their jar to WARNING.

我尝试使用-Djava.util.logging.config.file = pathToMy/JUL.properties的VM参数 文件内容在哪里:

I have tried using the VM argument of -Djava.util.logging.config.file=pathToMy/JUL.properties where the contents of the file are:

handlers=java.util.logging.ConsoleHandler
.level=WARNING
java.util.logging.ConsoleHandler.level=WARNING

不幸的是,这并没有影响输出.

Unfortunately, that made no difference in the output.

如果更简单,我的应用程序将使用SLF4J.因此,如果有使用其他日志记录机制的简单答案,我可以切换绑定以使用它.

If it makes it any easier, my application uses SLF4J. So if there's a simple answer using a different logging mechanism I can just switch my binding to use it.

推荐答案

您是否使用过

  • 虚拟机摘要"选项卡显示已设置系统属性"java.util.logging.config.file".
  • 空白(无值)的MBean选项卡-> java.util.logging-> Operations-> getLoggerLevel返回警告.
  • "MBean"选项卡-> java.util.logging-> Attributes-> LoggerNames包含活动的第三方记录器的列表,可以将其添加到要禁用的事物列表中.仅当执行代码创建记录器时,才会列出记录器. 匿名记录器是未列出,但默认设置是从root记录器继承的.
    1. The VM Summary tab shows that the system property 'java.util.logging.config.file' is set.
    2. The MBean tab->java.util.logging->Operations->getLoggerLevel of blank (no value) returns WARNING.
    3. The MBean tab->java.util.logging->Attributes->LoggerNames contains the list of active 3rd party loggers which can be added to your list of things to disable. The loggers will only be listed if the executing code has created them. Anonymous loggers are not listed but, the default settings are inherited from the root logger.

    您还可以添加以下代码来检查您的配置文件是否正常工作:

    You can also add the following code to check that your config file is working:

        public static void main(String[] arg) throws Exception {
            String p = System.getProperty("java.util.logging.config.file");
            System.out.println(p);
            System.out.println(new File(p).length());
            System.out.println(Logger.getLogger("").getLevel());
        }
    

    这篇关于从第3方jar抑制Java util日志记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆