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.
# 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=14Always 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
1. What logging framework does Spring Boot use by default when spring-boot-starter-logging is on the classpath?
2. How would you set DEBUG-level logging only for the com.example.orders package?
3. Why is structured JSON logging generally preferred over plain text in production systems?
4. What risk comes with leaving org.hibernate.SQL logging at DEBUG permanently in production?
5. What is the benefit of including a traceId in every log line for a request?
Was this page helpful?
You May Also Like
Spring Boot Actuator
How Spring Boot Actuator exposes production-ready monitoring endpoints for health checks, metrics, and application internals.
Application Properties and Profiles
How Spring Boot externalizes configuration through application.properties/yml, property precedence, and environment-specific profiles.
Spring Security Basics
An introduction to how Spring Security protects a Spring Boot application using the servlet filter chain, HTTP security rules, and password encoding.
Related Reading
Related Study Notes in Web Development
Browse all study notesWebSockets Study Notes
Web Development · 30 topics
Web DevelopmentWebAssembly Study Notes
WebAssembly · 30 topics
Web DevelopmentgRPC Study Notes
Protocol Buffers · 30 topics
Web DevelopmentFlask Study Notes
Python · 30 topics
Web DevelopmentDjango Study Notes
Python · 30 topics
Web DevelopmentNext.js Study Notes
JavaScript · 30 topics