How to disable JAudioTagger Logger completely
Asked Answered
D

2

7

Have been using JAudioTagger library for 2 years now , i can't figure out how to disable the Logger of it.

Also asked the owner of the project : 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 ? The console is almost unusable because of tons of JAudioTagger messages .

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 .


Solution 27/06/2018 For people interested :)

static {

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

    for (Logger l : pin)
        l.setLevel(Level.OFF);
}
Doorknob answered 9/6, 2018 at 20:53 Comment(1)
heh, back in the day, I wasn't very patient and forked this library in my code and ripped out all the logging. It became twice as fast too :) Not a recommended solution, though.Toneless
P
3

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

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.

Promote answered 9/6, 2018 at 22:32 Comment(1)
Great answer :) Can you provide some code please for the SimpleFormatter, i am like O_o For example i want to know all the logger names but instead i am getting '' '' empty spaces.Doorknob
G
2

You can define a config for the java.util.logging used in the jaudiotagger library

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
Greyhen answered 30/4, 2019 at 14:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.