how do I change log level in runtime without restarting spring boot application

后端 未结 10 1020
北荒
北荒 2020-12-23 19:55

I have deployed springboot application in PCF . I want to log the message based on the environment variable .What should I do so that the run time log level change will work

10条回答
  •  清酒与你
    2020-12-23 20:21

    For Spring Boot 2.1.5+:

    First, you need the actuator Plugin:

    
        org.springframework.boot
        spring-boot-starter-actuator
    
    

    Second, you need to expose the endpoint like Dennis said in his comment (loggers is disabled by default):

    management.endpoints.web.exposure.include=health,info,loggers
    

    Finally, you can use the Rest Endpoints to get Information about the loggers and set the logging levels.

    curl -X "GET" "http://localhost:8080/actuator/loggers"
    

    To set the Root logging Level you can use

    curl -X "POST" "http://localhost:8080/actuator/loggers/ROOT" -H "Content-Type: application/json; charset=utf-8"   -d $'{ "configuredLevel": "INFO" }'
    

提交回复
热议问题