Spring Boot uses Commons Logging for all its internal logging but leaves the underlying implementation open. When you use the Spring Boot starters, Logback is configured by default, with appropriate routing bridges so that libraries using Java Util Logging, Log4J, or SLF4J all feed into the same Logback pipeline. You do not need to change logging dependencies — the defaults work for most applications.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/spring-projects/spring-boot/llms.txt
Use this file to discover all available pages before exploring further.
Default log format
The default output from Spring Boot looks like this:- Date and time — millisecond precision, ISO 8601 format
- Log level —
ERROR,WARN,INFO,DEBUG, orTRACE - Process ID
---separator — marks the start of the actual log message- Application name — in brackets, only if
spring.application.nameis set - Thread name — in brackets, may be truncated
- Logger name — usually the source class name, often abbreviated
- Log message
Logback does not have a
FATAL level. Log4J2’s FATAL events are mapped to ERROR in Logback.Setting log levels
Set log levels for any package or class inapplication.properties or application.yaml using logging.level.<logger-name>=<level>:
root key configures the root logger, which acts as the default level for all loggers not explicitly configured.
You can also set levels via environment variables. LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_WEB=DEBUG sets org.springframework.web to DEBUG. This technique works at the package level only — for class-level configuration, use SPRING_APPLICATION_JSON.
Debug and trace modes
Start with--debug to configure a selection of core loggers (embedded container, Hibernate, Spring Boot) at DEBUG level without changing your own code’s log level:
--trace for even more verbose output from the same core loggers:
Writing to a file
By default, Spring Boot logs only to the console. To also write to a file, set one of these properties:spring.log to a directory:
logging.file.path is ignored and only logging.file.name is used. Log files rotate automatically when they reach 10 MB.
Logback rotation policy
Fine-tune Logback’s rolling policy directly fromapplication.properties:
Log groups
Group related loggers together so you can configure them all with one setting:| Group | Loggers |
|---|---|
web | org.springframework.core.codec, org.springframework.http, org.springframework.web, org.springframework.boot.actuate.endpoint.web, org.springframework.boot.web.servlet.ServletContextInitializerBeans |
sql | org.springframework.jdbc.core, org.hibernate.SQL, org.jooq.tools.LoggerListener |
Custom log configuration
Place a Logback or Log4j2 configuration file in the classpath root. Spring Boot picks it up automatically:| Logging system | Files loaded |
|---|---|
| Logback | logback-spring.xml, logback-spring.groovy, logback.xml, logback.groovy |
| Log4j2 | log4j2-spring.xml, log4j2.xml |
| Java Util Logging | logging.properties |
Logback environment properties
Insidelogback-spring.xml, expose Spring Environment properties using the <springProperty> tag:
Switching to Log4j2
To use Log4j2 instead of Logback, exclude the default Logback dependency and add the Log4j2 starter:- Maven
- Gradle
Structured logging (Spring Boot 3.4+)
Structured logging writes log output in a machine-readable format — typically JSON — that log ingestion pipelines (Elasticsearch, Graylog, Logstash) can parse without custom regex patterns. Enable structured logging with a single property:- ECS (Elastic Common Schema)
- GELF (Graylog)
- Logstash JSON
Customizing structured JSON output
Adjust field names and content using thelogging.structured.json properties:
Startup info logging
Setspring.main.log-startup-info=false to suppress the startup banner and active-profile summary that Spring Boot prints at INFO level when the application starts.