Enterprise Java
Spring Boot – Configure Log Level in runtime using actuator endpoint
As of Spring Boot 1.5 a new loggers
actuator endpoint allows viewing and changing application logging levels in runtime.
- Add
spring-boot-actuator
to your project
1 2 3 4 | < dependency > < groupId >org.springframework.boot</ groupId > < artifactId >spring-boot-starter-actuator</ artifactId > </ dependency > |
- Disable security for
loggers
or 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):
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | { "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:
1 | /logger/{logger} |
Examples:
01 02 03 04 05 06 07 08 09 10 11 12 13 | λ 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:
1 | curl -i -X POST -H 'Content-Type: application/json' -d '{"configuredLevel": "TRACE"}' http: //localhost:8080/loggers/ROOT |
Source 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. |
Spring Boot – Configure Log Level in run time using actuator endpoint for multiple instance of a spring micro services