Skill 114 · Create Spring Boot Java Project
Subchapter 114.4
references/logging.mdMarkdown2 KBView on GitHub
Spring Boot logs with Logback through SLF4J by default. Code must depend only on the SLF4J API (org.slf4j.Logger), never on Logback or System.out.
private static final Logger logger = LoggerFactory.getLogger(OrderService.class);
ERROR = needs attention; WARN = recoverable anomaly; INFO = business events and lifecycle; DEBUG/TRACE = diagnostics (off in production).logging.level.root=INFO
logging.level.com.example=INFO
# dev profile: logging.level.com.example=DEBUGPrefer properties over a custom logback-spring.xml; add the XML only for needs properties cannot cover (appenders, rolling files).
For production and log aggregation, emit JSON without extra dependencies:
logging.structured.format.console=ecsOther built-in formats: logstash, gelf. In containers, log to the console and let the platform collect it.
Use Micrometer Tracing / the spring-observability skill so trace and span ids appear in logs; use MDC for request-scoped values (MDC.put("requestId", ...), always cleared in finally).