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

Abierto Apto para principiantes
#52,646 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
76/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
java, spring-boot

Línea de trabajo

Empieza con JavaLoggingSystem#getLoggerConfiguration y compara la búsqueda de logger con la asignación del nombre raíz en setLogLevel. Revisa en JavaLoggingSystemTests si hay cobertura para las búsquedas de loggers raíz y desconocidos, y luego ejecuta esos tests. Se considera terminado cuando ROOT devuelve el nivel configurado y un logger desconocido se notifica como inexistente sin registrarlo.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

status: waiting-for-triage

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.

Lenguaje dominante
Java
Estrellas
81.8k
Forks
43.5k
Merge medio
3 d 13 h
PR fusionados (30 d)
90

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de spring-projects/spring-boot

Todos los issues de spring-projects/spring-boot

Issues similares

Más issues de Java

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.