100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Java

Logging in Spring Boot

How Spring Boot's default Logback-based logging works, including log levels, per-package configuration, and structured logging for production.

Security & ConfigBeginner7 min readJul 10, 2026
Analogies

Spring Boot's Default Logging Setup

Spring Boot uses Commons Logging as its logging facade but ships Logback as the default underlying implementation via spring-boot-starter-logging, which is pulled in transitively by nearly every starter, meaning most projects get sensible console logging with zero configuration. Logback provides a color-coded console pattern out of the box showing timestamp, log level, process ID, thread name, logger name, and message, and Spring Boot auto-detects a logback-spring.xml on the classpath if you need to customize appenders, patterns, or rolling file policies beyond what application.properties exposes.

🏏

Cricket analogy: It's like a stadium's default PA announcer calling out every wicket and boundary automatically without a producer needing to configure anything — Logback's default console output works the same way out of the box.

Log Levels and Per-Package Configuration

Logback supports the standard severity levels TRACE, DEBUG, INFO, WARN, and ERROR, and you configure the minimum level per logger namespace using properties like logging.level.com.example.orders=DEBUG or logging.level.root=WARN, which lets you drill into verbose detail for one troublesome package while keeping the rest of the application quiet. This granularity matters in production: setting logging.level.org.hibernate.SQL=DEBUG temporarily during an investigation shows every SQL statement Hibernate executes, but leaving it on permanently would flood log storage and potentially expose sensitive query parameter values in log aggregation tools.

🏏

Cricket analogy: It's like a broadcaster choosing to zoom the camera in tight on just the bowler's wrist position (DEBUG) for one review, while keeping the wide-angle shot (INFO) for the rest of the over.

Structured Logging for Production

Plain text console logs are easy for a human to read during local development but painful to search and correlate at scale, so production systems typically emit structured JSON logs instead, where each field (timestamp, level, logger, message, traceId) is a distinct JSON key that log aggregators like Elasticsearch, Loki, or Splunk can index and query directly. Spring Boot 3.4+ includes native structured logging support via logging.structured.format.console=ecs (or logstash/gelf formats), and pairing this with Micrometer Tracing to inject a traceId and spanId into every log line lets you pivot from a single log message straight to the full distributed trace of a request across multiple microservices.

🏏

Cricket analogy: It's like moving from a handwritten scorebook to ball-by-ball structured data feeds — every delivery becomes a queryable record (bowler, speed, outcome) instead of prose a human must re-read to find a pattern.

properties
# application.properties
logging.level.root=INFO
logging.level.com.example.orders=DEBUG
logging.level.org.hibernate.SQL=WARN

# Structured JSON logging (Spring Boot 3.4+)
logging.structured.format.console=ecs
logging.file.name=logs/order-service.log
logging.logback.rollingpolicy.max-file-size=50MB
logging.logback.rollingpolicy.max-history=14

Always include a correlation or trace ID in every log line for a request, either manually via MDC.put("traceId", id) or automatically via Micrometer Tracing integration. Without it, correlating the dozens of log lines produced by a single request across a multi-threaded, multi-service system becomes a manual, error-prone timestamp-matching exercise.

  • Spring Boot uses Logback by default via spring-boot-starter-logging, working with zero configuration.
  • Log levels (TRACE, DEBUG, INFO, WARN, ERROR) can be set per package via logging.level.<package>.
  • Temporarily raising a package's log level is useful for debugging without flooding the whole app's logs.
  • Structured JSON logging makes logs queryable by tools like Elasticsearch, Loki, or Splunk.
  • Spring Boot 3.4+ has native support for structured logging formats like ECS and Logstash.
  • Micrometer Tracing can inject traceId/spanId into logs for cross-service request correlation.
  • logback-spring.xml allows full customization of appenders, patterns, and rolling file policies.

Practice what you learned

Was this page helpful?

Topics covered

#Java#SpringBootStudyNotes#WebDevelopment#LoggingInSpringBoot#Logging#Spring#Boot#Default#StudyNotes#SkillVeris