Spring Boot

Logging with SLF4J & Logback

Logging with SLF4J and Logback, log levels, configuration, appenders, patterns, package-level logging

20 perguntas de entrevista·
Junior
1

What is SLF4J in the Java ecosystem?

Resposta

SLF4J (Simple Logging Facade for Java) is an abstraction facade for various Java logging frameworks (Logback, Log4j, JUL). It allows decoupling application code from the concrete logging implementation, making it easy to change frameworks without modifying business code. Spring Boot uses SLF4J with Logback as the default implementation.

2

What is the default logging implementation in Spring Boot?

Resposta

Logback is the default logging implementation in Spring Boot. Developed by the creator of Log4j, Logback offers better performance, more flexible configuration, and native SLF4J compatibility. Spring Boot includes it automatically via spring-boot-starter-logging which is a transitive dependency of all web starters.

3

How to create a Logger instance with SLF4J in a Spring class?

Resposta

The recommended method is LoggerFactory.getLogger(ClassName.class) which creates a logger based on the fully qualified class name. This enables a consistent logger hierarchy with Java packages and simplifies configuration by package. Alternatively, Lombok provides @Slf4j which automatically generates the logger.

4

What are the standard log levels in SLF4J, from most verbose to most critical?

5

Which Spring Boot property sets the log level for a specific package?

+17 perguntas de entrevista

Domine Spring Boot para sua proxima entrevista

Acesse todas as perguntas, flashcards, testes tecnicos, exercicios de code review e simuladores de entrevista.

Comece gratis