Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 23
Logging Basics
Spring Boot uses SLF4J as the API and Logback as the default implementation.
Course progress0%
Focus
3 guided sections
Practice signal
Examples included
Career prep
Foundation builder
Introduction
Spring Boot uses SLF4J as the API and Logback as the default implementation. Log structured JSON in production, human-readable in dev — no System.out.println ever.
Informative example
ts
@Service@Slf4j // Lombok – generates 'private static final Logger log = ...'public class OrderService {public Order place(NewOrder cmd) {log.info("Placing order user={} items={}", cmd.userId(), cmd.items().size());try {...} catch (Exception ex) {log.error("Order placement failed user={}", cmd.userId(), ex);throw ex;}}}# application.ymllogging:level:root: INFOcom.acme: DEBUGpattern:console: "%d{ISO8601} %-5level [%thread] %logger - %msg%n"
Best practices
- Log levels: TRACE → DEBUG → INFO → WARN → ERROR. Default INFO in prod.
- Use parameterised messages (
log.info("x={}", x)) — lazy formatting. - Add a correlation/trace ID to every request via
MDC.
Ready to mark this lesson complete?Track your journey across the entire course.