spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

JavaLoggingSystem.getLoggerConfiguration does not map ROOT and creates unknown loggers on lookup

Open Ludocius opened this issue 4 weeks ago • 3 comments

When JavaLoggingSystem is used, getLoggerConfiguration(String) behaves differently from setLogLevel and from the Logback and Log4j2 implementations:

  1. ROOT is not mapped to the JUL root logger "" (setLogLevel does this mapping), so the lookup returns a child logger literally named ROOT.
  2. Logger.getLogger(name) creates the logger on demand and never returns null, so an unknown logger is never reported as missing.

As a result, the loggers actuator endpoint behaves inconsistently with JUL:

Spring Boot 4.1.2, -Dorg.springframework.boot.logging.LoggingSystem=org.springframework.boot.logging.java.JavaLoggingSystem, management.endpoints.web.exposure.include=loggers:

POST /actuator/loggers/ROOT {"configuredLevel":"DEBUG"}  -> 204
GET  /actuator/loggers/ROOT                             -> 200 {"effectiveLevel":"DEBUG"}        // configuredLevel missing
GET  /actuator/loggers/no.such.logger                   -> 200 {"effectiveLevel":"DEBUG"}        // Logback/Log4j2 return 404

GET /actuator/loggers does list ROOT with configuredLevel: DEBUG, because there the name "" comes from LogManager, so the single-logger and all-loggers views disagree. Each lookup of an unknown name also permanently registers a new JUL logger.

Expected (same as with Logback/Log4j2):

GET  /actuator/loggers/ROOT            -> 200 {"configuredLevel":"DEBUG","effectiveLevel":"DEBUG"}
GET  /actuator/loggers/no.such.logger  -> 404

The relevant code is JavaLoggingSystem#getLoggerConfiguration (unchanged since 2016). Commit 1d2f6d25fa ("Use consistent 'ROOT' logger name") aligned setLogLevel only. A minimal change that fixes both points:

if (ROOT_LOGGER_NAME.equals(loggerName)) {
	loggerName = "";
}
Logger logger = LogManager.getLogManager().getLogger(loggerName);

I verified this with an end-to-end test (@SpringBootTest(webEnvironment = RANDOM_PORT) plus real HTTP calls) against 4.1.2 (fails) and against a locally built spring-boot jar with the change above (passes). The existing JavaLoggingSystemTests also still pass. I'm happy to share the sample or submit a PR with tests if that's useful.

Ludocius avatar Nov 07 '26 13:11 Ludocius

"Hi @Ludocius, are you currently working on a PR for this? If you haven't started on one, I'd be happy to help submit a PR with the tests.

manthansharma6767 avatar Nov 18 '26 17:11 manthansharma6767

"Hi @Ludocius, are you currently working on a PR for this? If you haven't started on one, I'd be happy to help submit a PR with the tests.

@manthansharma6767 Please, feel free to proceed.

Ludocius avatar Nov 18 '26 19:11 Ludocius

Closing in favor of PR #52826. Thanks @manthansharma6767

philwebb avatar Nov 18 '26 23:11 philwebb