As of Spring Boot 1.5 a new loggers actuator endpoint allows viewing and changing application logging levels in runtime.
- Add
spring-boot-actuatorto your project
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
- Disable security for
loggersor for all endpoints
Set either management.security.enabled to false or endpoints.loggers.sensitive to false to disable security. Note that the latter changes only loggers endpoint.
- Get all loggers details
Execute /loggers endpoint in the browser or with curl. You will get a detailed view of the loggers configuration, e.g (fragment):
{
"levels": [
"OFF",
"ERROR",
"WARN",
"INFO",
"DEBUG",
"TRACE"
],
"loggers": {
"ROOT": {
"configuredLevel": "TRACE",
"effectiveLevel": "TRACE"
},
"org": {
"configuredLevel": null,
"effectiveLevel": "TRACE"
},
"pl.codeleak.demos.sbt": {
"configuredLevel": null,
"effectiveLevel": "TRACE"
},
"pl.codeleak.demos.sbt.Application": {
"configuredLevel": null,
"effectiveLevel": "TRACE"
}
}
}- Get selected logger details
Use the following endpoint to get details of a selected logger:
/logger/{logger}Examples:
Ξ» curl -i http://localhost:8080/loggers/ROOT
{
"configuredLevel": null,
"effectiveLevel": "TRACE"
}
Ξ» curl -i http://localhost:8080/loggers/pl.codeleak.demos
{
"configuredLevel": null,
"effectiveLevel": "TRACE"
}- Update selected logger level in runtime
Execute a POST request:
curl -i -X POST -H 'Content-Type: application/json' -d '{"configuredLevel": "TRACE"}' http://localhost:8080/loggers/ROOTSource code
The example configuration can be found in https://github.com/kolorobot/spring-boot-thymeleaf repository.
| Reference: | Spring Boot β Configure Log Level in runtime using actuator endpoint from our JCG partner Rafal Borowiec at the Codeleak.pl blog. |
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy
Thank you!
We will contact you soon.
Tags
Logging Spring Spring Boot
π Photo of Rafal Borowiec
Rafal BorowiecMarch 8th, 2017Last Updated: March 7th, 2017
Rafal BorowiecMarch 8th, 2017Last Updated: March 7th, 2017
1 447 1 minute read

This site uses Akismet to reduce spam. Learn how your comment data is processed.
Spring Boot β Configure Log Level in run time using actuator endpoint for multiple instance of a spring micro services