0

Despite consulting the answers to this question, my Logger will never show messages of level FINE and below.

Logger root = Logger.getLogger("");
root.setLevel(Level.FINEST); // I have also tried Level.ALL
    
// Test messages
root.severe("Severe");
root.warning("Warning");
root.info("Info");
root.fine("Fine");
root.finer("Finer");
root.finest("Finest");

The code produces the following output.

Nov 27, 2021 4:28:45 PM java.util.logging.LogManager$RootLogger log
SEVERE: Severe
Nov 27, 2021 4:28:45 PM java.util.logging.LogManager$RootLogger log
WARNING: Warning
Nov 27, 2021 4:28:45 PM java.util.logging.LogManager$RootLogger log
INFO: Info

I have tried updating the logging.properties file to set the ConsoleHandler's level to ALL and FINEST, but that does not change my results. How do I actually change the level of my logger?

My logging.properties:

handlers= java.util.logging.ConsoleHandler
.level= ALL

java.util.logging.FileHandler.pattern = %h/java%u.log
java.util.logging.FileHandler.limit = 50000
java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = java.util.logging.XMLFormatter

java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
MAO3J1m0Op
  • 423
  • 3
  • 14
  • Please provide your logging configuration also - content of the `logging.properties` file or configuration done in the code. Most likely you did not set proper logging level for the `ConsoleHandler`. By default, it is set to `java.util.logging.ConsoleHandler.level = INFO` in the `logging.properties` file provided with JDK. Look at the `Editing the handler Level` section in the SO answer you referred to how to do this. – Sergei Nov 27 '21 at 22:40
  • Where is logging.properties located? Are you sure it’s in the same JRE or JDK that you are using when you run the program? – VGR Nov 28 '21 at 16:11

1 Answers1

1

Use the test program to print the logger tree and post the console output. This will prove if your static configuration file is actually being used at runtime.

It shouldn't be a problem for the root logger but you should declare your logger as static final so it doesn't get garbage collected and you lose all of your progmatic changes.

jmehrens
  • 10,580
  • 1
  • 38
  • 47