How to Set Log Level in Spring Boot: Simple Guide
In Spring Boot, you set the log level by adding
logging.level.<logger-name>=<level> in your application.properties or application.yml file. For example, logging.level.org.springframework=DEBUG sets the Spring framework logs to debug level.Syntax
Use the property logging.level.<logger-name>=<level> in your configuration file. Replace <logger-name> with the package or class name you want to control, and <level> with one of the log levels: TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF.
Example: logging.level.com.example=INFO sets the log level for the com.example package to INFO.
properties
logging.level.<logger-name>=<level>
Example
This example shows how to set the root log level to WARN and a specific package to DEBUG in application.properties. It controls the verbosity of logs for easier troubleshooting.
properties
logging.level.root=WARN logging.level.org.springframework.web=DEBUG
Output
Logs from Spring Web package will show DEBUG and above, while other logs show WARN and above.
Common Pitfalls
- Forgetting to specify the correct logger name causes the setting to have no effect.
- Setting log level in the wrong configuration file or profile can lead to confusion.
- Using uppercase or lowercase inconsistently in log levels might cause issues; always use uppercase.
- Setting
logging.level.rootaffects all logs globally, so use it carefully.
properties
Wrong: logging.level.org.springframework=debug Right: logging.level.org.springframework=DEBUG
Quick Reference
| Property | Description | Example |
|---|---|---|
| logging.level.root | Sets log level for all packages | logging.level.root=INFO |
| logging.level. | Sets log level for specific package | logging.level.com.example=DEBUG |
| logging.level. | Sets log level for specific class | logging.level.com.example.MyClass=TRACE |
| Log Levels | Available levels | TRACE, DEBUG, INFO, WARN, ERROR, FATAL, OFF |
Key Takeaways
Set log levels in Spring Boot using logging.level.= in application.properties or application.yml.
Use uppercase for log levels like DEBUG, INFO, WARN to avoid issues.
logging.level.root controls global log level; use it carefully.
Specify exact package or class names to control log verbosity precisely.
Check active profiles and configuration files to ensure log settings apply.