简体   繁体   English

如何完全禁用JAudioTagger Logger

[英]How to disable JAudioTagger Logger completely

Have been using JAudioTagger library for 2 years now , i can't figure out how to disable the Logger of it. 已经使用JAudioTagger库2年了,我无法弄清楚如何禁用它的Logger。

Also asked the owner of the project : https://bitbucket.org/ijabz/jaudiotagger/issues/257/how-to-disable-jaudio-tagger-logger 还询问了该项目的所有者: https//bitbucket.org/ijabz/jaudiotagger/issues/257/how-to-disable-jaudio-tagger-logger

What i have tried ? 我试过了什么? ( No luck ) ( 没运气 )

Logger.getLogger("org.jaudiotagger").setLevel(Level.OFF);
Logger.getLogger("org.jaudiotagger.tag").setLevel(Level.OFF);
Logger.getLogger("org.jaudiotagger.audio.mp3.MP3File").setLevel(Level.OFF);
Logger.getLogger("org.jaudiotagger.tag.id3.ID3v23Tag").setLevel(Level.OFF);

For now i just have disabled the Logger generally from the application , but i need it , what can i do ? 现在我只是从应用程序中禁用了Logger,但我需要它,我该怎么办? The console is almost unusable because of tons of JAudioTagger messages . 由于大量的JAudioTagger消息,控制台几乎无法使用。

Temporary Solution ( I need the logger for the application though ...) 临时解决方案(我需要应用程序的记录器......)

LogManager.getLogManager().reset();

I have searched all the web , i can't find a solution like it's been 2 years ... that's why i ask here . 我搜索了所有的网络,我找不到像这样的解决方案已经2年......这就是我在这里问的原因。


Solution 27/06/2018 For people interested :) 解决方案 27/06/2018对于有兴趣的人:)

static {

    //Disable loggers               
    pin = new Logger[]{ Logger.getLogger("org.jaudiotagger") };

    for (Logger l : pin)
        l.setLevel(Level.OFF);
}

You have to hold a strong reference to your loggers . 您必须对记录器有强烈的引用 Otherwise, your level change is ignored when the logger is garbage collected. 否则,当记录器被垃圾收集时,将忽略您的级别更改。

The logger name needs to match the logger used in JAudioTagger. 记录器名称需要与JAudioTagger中使用的记录器匹配。 You can find the logger names by viewing the source code. 您可以通过查看源代码找到记录器名称。 Otherwise, change the format of the SimpleFormatter to include the logger name which is %3$s (the javadocs are off by one). 否则,更改SimpleFormatter格式以包含记录器名称 ,即%3$s (javadocs关闭一个)。 When you run your program this will list the logger names you need to turn off. 运行程序时,将列出需要关闭的记录器名称。

Use the formatter test program to ensure that you format property is configured correctly. 使用格式化程序测试程序以确保正确配置格式属性。 Your pattern can be as simple as the pattern above or something with a little more detail like %1$tH:%1$tM:%1$tS.%1$tL - [%3$s] -[%4$s] %5$s%n 您的模式可以像上面的模式一样简单,也可以更详细一些,例如%1$tH:%1$tM:%1$tS.%1$tL - [%3$s] -[%4$s] %5$s%n

Another option would be to add code to list all loggers just before your program exits. 另一种选择是在程序退出之前添加代码以列出所有记录器。

private static void findFormatters() {
    final LogManager manager = LogManager.getLogManager();
    synchronized (manager) {
        final Enumeration<String> e = manager.getLoggerNames();
        while (e.hasMoreElements()) {
            System.out.println(e.nextElement());
        }
    }    
}

JConsole can also list all of the active loggers. JConsole还可以列出所有活动记录器。

You can define a config for the java.util.logging used in the jaudiotagger library 您可以为jaudiotagger库中使用的java.util.logging定义配置

static {
    java.util.logging.LogManager manager = java.util.logging.LogManager.getLogManager();
    try {
        manager.readConfiguration(new FileInputStream("audioLogger.properties"));
    } catch (IOException ignored) {}
}

and then configure the logging in the specified properties file 然后在指定的属性文件中配置日志记录

handlers=java.util.logging.ConsoleHandler
org.jaudiotagger.level=OFF

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM