JavaLoggingSystem.getLoggerConfiguration does not map ROOT and creates unknown loggers on lookup
When JavaLoggingSystem is used, getLoggerConfiguration(String) behaves differently from setLogLevel and from the Logback and Log4j2 implementations:
ROOTis not mapped to the JUL root logger""(setLogLeveldoes this mapping), so the lookup returns a child logger literally namedROOT.Logger.getLogger(name)creates the logger on demand and never returnsnull, 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.
"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.
"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.
Closing in favor of PR #52826. Thanks @manthansharma6767