0

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.

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.

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.

Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
user2992188
  • 283
  • 1
  • 5
  • 18

3 Answers3

3

I think you may have the following snippet useful. It will allow you to set the log behaviour at package level:

Logger logger = Logger.getLogger("org.apache.axiom");
logger.setLevel(Level.WARN);
Luiggi Mendoza
  • 85,076
  • 16
  • 154
  • 332
  • There's no need to use signature in your posts. Note that at the bottom it appears your user name and the avatar you choose for your account. – Luiggi Mendoza Oct 21 '14 at 15:32
  • I've tried that as well but to no avail. That's why I also tried via properties file and made a blanket statement to set everything to warning – user2992188 Oct 21 '14 at 15:34
  • By far the best answer. Simple, independant of any IDE, tools or "tabs", no additional config files needed and no change of library. And works like a charm. – ospf Mar 14 '18 at 09:15
2

Have you used JConsole to determine that:

  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());
    }
jmehrens
  • 10,580
  • 1
  • 38
  • 47
  • I followed all your steps above and everything looks correct except for #3. I do not see the list of active 3rd party loggers. How are they getting output to console then, and can they be disabled? – user2992188 Oct 22 '14 at 11:02
  • I updated the answer to include some reasons why they are not listed. Is it using the global logger? – jmehrens Oct 22 '14 at 13:06
  • Unfortunately I had to get the 3rd party developer to add the properties file directly to their jar. I am awarding points for providing useful information and for helping out :) – user2992188 Nov 07 '14 at 14:52
0

Before decompile the jar to find how to set Log level you can try to search the setLogLevel api for which component you want debug more.

enter image description here

setLogWriter(new PrintWriter(System.out));

suiwenfeng
  • 1,865
  • 1
  • 25
  • 32