0

I'm using a JDK14Logger implementation to apache commons-loggings framework. The debug logs are not appearing, and they appear only when I set the root logger to FINE. My understanding is that log level set to specific handlers should override log level of root logger. However, that is not happening.

# The following creates the console handler
handlers=java.util.logging.ConsoleHandler, java.util.logging.FileHandler

# Set the default logging level for the root logger
.level=FINE

# Set the default logging level
java.util.logging.ConsoleHandler.level=FINE
java.util.logging.FileHandler.level=FINEST

# log level for the "com.rst.example" package


# Set the default formatter
java.util.logging.ConsoleHandler.formatter=java.util.logging.SimpleFormatter
java.util.logging.FileHandler.formatter=java.util.logging.SimpleFormatter

# Specify the location and name of the log file
java.util.logging.FileHandler.pattern=D:/test.log

test class:

public class Test {
private  Log logger = LogFactory.getLog(Test.class.getName());

 static  {
    System.getProperties().setProperty("java.util.logging.config.file","log-config.properties");
}

public static void main(String[] args) {
    //-Djava.util.logging.config.file=src/main/resources/log-config.properties

    Test test =  new Test();

    test.logger.info("info from main");
    test.logger.error("error from main");
    test.logger.fatal("fatal from main");
    System.out.println("is dubug enabled? :" + test.logger.isDebugEnabled());
    test.logger.debug("debug from main");

}

}

Imran pasha
  • 31
  • 1
  • 8

1 Answers1

0

All JDK loggers will publish log records to the handlers of the root logger by default. The default level for the ConsoleHandler is INFO.

My understanding is that log level set to specific handlers should override log level of root logger. However, that is not happening.

It doesn't and it is not. Use DebugLogging to test your configuration file against the JDK logging.

The debug logs are not appearing, and they appear only when I set the root logger to FINE.

Output is published to a handler. Not appearing either means that your handler is not attached, the level is not set to what you expect, or the handler is attached to a child logger that is not on the publishing path.

Modify the DebugLogging class in the linked answer to include your configuration and the apache-commons code that performs logging. Don't delete the JDK logging code. The output from that code will direct you to the problem.

jmehrens
  • 10,580
  • 1
  • 38
  • 47