Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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);
}
like image 623
GOXR3PLUS Avatar asked Jun 09 '18 20:06

GOXR3PLUS


2 Answers

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.

like image 149
jmehrens Avatar answered Oct 22 '22 16:10

jmehrens


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
like image 27
flederohr Avatar answered Oct 22 '22 17:10

flederohr