What is Spring Boot logging?
Why Interviewers Ask This
This question tests conceptual clarity. Interviewers want to hear a precise, confident definition before moving to more complex Spring Boot topics. It also reveals how well you can explain technical ideas to non-experts.
Answer
Spring Boot uses SLF4J (Simple Logging Facade for Java) as the logging API and Logback as the default implementation (included in spring-boot-starter). Using a logger: import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Service public class UserService { private static final Logger log = LoggerFactory.getLogger(UserService.class); public User createUser(String email) { log.debug("Creating user: {}", email); // {} is placeholder try { User user = userRepository.save(new User(email)); log.info("User created: id={}, email={}", user.getId(), email); return user; } catch (Exception e) { log.error("Failed to create user: {}", email, e); throw e; } } }. Lombok shortcut: @Slf4j annotation generates the log field automatically. Log levels (lowest to highest): TRACE, DEBUG, INFO (default), WARN, ERROR. Configuration in application.properties: logging.level.root=WARN logging.level.com.example=DEBUG logging.level.org.springframework.web=INFO logging.file.name=app.log logging.file.path=/var/log/app logging.pattern.console=%d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n. Logback configuration (logback-spring.xml): for advanced configuration — rolling policies, appenders, filters. Use logback-spring.xml (not logback.xml) to use Spring Boot's extensions including profile-specific config. Structured logging: use logstash-logback-encoder for JSON logs in production. Log4j2: exclude logback, add log4j2 starter for alternative implementation.
Pro Tip
Back up your answer with a specific project or situation. Saying 'In my last Spring Boot project, I used this when...' immediately makes your answer more credible and memorable.