When troubleshooting Spring Boot applications—especially in production—debug logging is often the key to understanding what’s going wrong.
This guide explains:
- What debug logging actually means
- Why it’s important
- How Spring Boot logging works
- How to enable debug logs thoroughly and safely
- How to narrow debug output when needed
- Production-safe logging approaches
Whether you’re diagnosing startup failures, configuration issues, bean creation problems, or runtime exceptions, having the right logging setup dramatically improves your troubleshooting power.
What Is Debug Logging?
Debug logging is a higher verbosity level in application logs that reveals internal details such as:
- Method entry/exit
- Lifecycle events
- Property resolution
- Bean initialization
- Dependency injection activity
- SQL operations
- Configuration source origins
This contrasts with:
- INFO level – general application behavior
- WARN level – potential issues
- ERROR level – failures and exceptions
Debug logs provide contextual insights developers need during complex failure investigations.
How Spring Boot Logging Works
Spring Boot uses:
- SLF4J (Simple Logging Facade for Java) as the logging API
- Logback as the default logging implementation
When your app starts, Spring Boot configures Logback automatically based on your environment.
Behind the scenes:
- Logback reads configuration (
logback.xml,application.properties, orapplication.yml) - It initializes appenders (console, file, etc.)
- It sets log levels per package
This works uniformly across:
- Local development
- CI/CD pipelines
- Production servers
- Containers (Docker, Kubernetes)
Enable Debug Logging (Simple Way)
In application.properties
logging.level.root=DEBUG
This enables debug logging across the entire application.
But in a large system, this may be too noisy.
In application.yml
logging:
level:
root: DEBUG
This sets the root log level to DEBUG.
You can refine this further for specific packages (shown below).
Enable Debug Logging for a Package Only
Often in production you want debug logs for only one part of the system (e.g., Spring framework, your business layer, or JPA).
Example – Framework & JPA
logging.level.org.springframework=DEBUG
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql=TRACE
This enables:
- Debug logs for Spring internals
- SQL statements emitted by Hibernate
- SQL parameter values (
TRACE)
This is critical when diagnosing:
- JPA mapping issues
- Query generation errors
- Transaction propagation problems
Enable Debug Logging at Runtime (Without Restart)
In production systems, sometimes you need debug logs without restarting the app:
If you use spring-boot-admin or actuator, you can change log levels dynamically.
Using Spring Boot Actuator
Make sure Actuator is enabled:
management.endpoints.web.exposure.include=*
Then call:
curl -X POST \
http://localhost:8080/actuator/loggers/org.springframework \
-H "Content-Type: application/json" \
-d '{"configuredLevel":"DEBUG"}'
This sets debug logging for the Spring framework package at runtime.
Logback vs Default Spring Boot Logging
Spring Boot auto-configures Logback for you. But in large projects, you may want custom logback.xml or logback-spring.xml for more control.
Example snippet in logback-spring.xml:
<configuration>
<include resource="org/springframework/boot/logging/logback/defaults.xml"/>
<logger name="org.springframework" level="DEBUG"/>
<root level="INFO">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>
This gives you full control over format, rotation, and appenders.
Logging in Multi-Profile Environments
In real production systems, you may want:
- DEBUG in dev
- INFO in prod
- ERROR in critical environments
Example with profiles:
spring:
profiles: dev
logging:
level:
root: DEBUG
And in application-prod.yml:
logging:
level:
root: INFO
When running with SPRING_PROFILES_ACTIVE=prod, production logs are cleaner.
For more on profiles and configuration loading:
https://springbootfixes.com/spring-boot-configuration-loading-order-production-guide/
Common Debug Logging Mistakes
Logging Too Much in Production
Setting DEBUG for all packages in production can:
- Fill up logs quickly
- Increase storage usage
- Hide real errors in noise
Solution:
Enable debug selectively (specific packages) and only when needed.
Not Using a Centralized Logging System
In production, logs should be aggregated using:
- ELK (Elasticsearch, Logstash, Kibana)
- Graylog
- Splunk
- Loki
This allows:
- Central searching
- Correlation by request ID
- Alerts on errors
How Logging Helps Diagnose Spring Boot Issues
Debug logging is especially useful for problems like:
Startup errors
Understanding why Spring fails to start.
Related:
https://springbootfixes.com/how-spring-boot-application-starts-startup-flow-explained/
Bean Creation Failures
Finding which bean failed and why.
Related:
https://springbootfixes.com/how-spring-boot-creates-beans-bean-lifecycle-simplified-for-production/
Configuration Issues
Seeing which configuration source provided a value.
Quick Debug Logging Checklist
When investigating production issues:
✔ Enable debug on suspect packages
✔ Check SQL logs for data problems
✔ Inspect config loading logs
✔ Adjust logs at runtime if supported
✔ Switch back to INFO once diagnosed
Summary
Debug logging is an indispensable part of diagnosing issues in Spring Boot applications — especially when:
- Auto-configuration fails
- Beans don’t load
- Profiles misbehave
- Database or messaging errors surface
By configuring logging wisely:
- You get actionable insights
- You maintain readable logs
- You avoid performance issues
Related Spring Boot Articles
Spring Boot Bean Lifecycle Simplified
https://springbootfixes.com/how-spring-boot-creates-beans-bean-lifecycle-simplified-for-production/
Spring Boot Startup Flow Explained
https://springbootfixes.com/how-spring-boot-application-starts-startup-flow-explained/
Spring Boot Configuration and Profiles
https://springbootfixes.com/spring-boot-configuration-and-profiles-explained-beginner-to-production-guide/
