To set different logging levels for specific packages in a Spring Boot application, you can configure them using the application.properties
or application.yml
file.
This allows you to control how much logging detail you get per package (e.g., your own code, Spring internals, Hibernate, etc.), which is useful for debugging specific modules without cluttering the logs.
Step-by-Step: Set Logging Levels in Spring Boot
1. Using application.properties
# Root logger level (global) logging.level.root=INFO # Set DEBUG for your application's packages logging.level.com.example.myapp=DEBUG # Reduce Spring logs to WARN logging.level.org.springframework=WARN # Show Hibernate SQL logs logging.level.org.hibernate.SQL=DEBUG # Hide Hibernate parameter logs logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
2. Using application.yml
logging: level: root: INFO com.example.myapp: DEBUG org.springframework: WARN org.hibernate.SQL: DEBUG org.hibernate.type.descriptor.sql.BasicBinder: TRACE
Common Log Levels (in order of verbosity)
Level | Description |
---|---|
TRACE | Most detailed, for fine-grained diagnostics |
DEBUG | Detailed info useful for debugging |
INFO | General application flow messages |
WARN | Potential issues or warnings |
ERROR | Errors that prevent normal flow |
OFF | Disable logging completely |
Tips
- Always keep
logging.level.root=INFO
in production unless troubleshooting. - Use
TRACE
orDEBUG
only for development – they can generate huge logs. - If you use external logging frameworks like Logback or Log4j2, you can fine-tune more settings in
logback-spring.xml
orlog4j2-spring.xml
.
Example Use Case
You are debugging a bug in your repository layer.
logging.level.com.example.myapp.repository=DEBUG
You want to see the actual SQL run by Hibernate:
logging.level.org.hibernate.SQL=DEBUG
Check Active Log Levels at Runtime (with Spring Actuator)
If you’re using Spring Boot Actuator:
- Add this to
application.properties
:management.endpoints.web.exposure.include=loggers
- Check active log levels:
GET /actuator/loggers
- Change logging level at runtime:
POST /actuator/loggers/com.example.myapp { "configuredLevel": "DEBUG" }