0

I am using java.util.logging to perform logging at different levels. My problem is that I can't get the levels FINE / FINER / FINEST to show any output. I have seen a similar thread (Why are the Level.FINE logging messages not showing?) which does not seem to solve my problem though. I have the following main class:

package logtest;

import java.util.logging.Logger;

public class Main {


    private static final Logger LOGGER = Logger.getLogger(Main.class.getName());

    public static void main(String[] args) {
        LOGGER.info("info");
        LOGGER.severe("severe");
        LOGGER.fine("fine");
    }

}

in a file src/logtest/Main.java and a file logging.properties in the root directory of my project:

.handlers = java.util.logging.ConsoleHandler

java.util.logging.ConsoleHandler.level = FINE
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter

I execute the generated binary (in bin/logtest) like this:

java -Djava.util.logging.config.file=logging.properties -classpath bin logtest.Main

and I get this result (observe that the FINE message is missing):

Aug 05, 2015 6:13:04 PM logtest.Main main
INFO: info
Aug 05, 2015 6:13:04 PM logtest.Main main
SEVERE: severe

Interestingly, if I change the entry java.util.logging.ConsoleHandler.level to SEVERE the first message disappears:

Aug 05, 2015 6:14:09 PM logtest.Main main
SEVERE: severe

So I know the file is read and interpreted correctly. But I just can't get the FINE logging message to show up on the console (using openjdk-8 btw). Any ideas as to why?

hfhc2
  • 4,182
  • 2
  • 27
  • 56

1 Answers1

2

You have changed the level on the handler, but not the logger. You'll need to do both.

You could do this in code:

LOGGER.setLevel(Level.FINE);

Or, you can read the settings from your properties file. To modify the default logging level, you can add:

.level=FINE

You can specify the logging levels for your own loggers by adding lines such as

com.mycompany.myapp.level=FINE
yas
  • 3,520
  • 4
  • 25
  • 38