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 without restarting the application?
In terms of scaling, the challenge is to change log levels in each instance. So to avoid all pitfalls following is needed: Dynamically change the log level at runtime without application restart. Propagation of log level changes across the application instances.
In Settings -> Config Vars set logging. level.com. yourpackage to the desired level (INFO, ERROR, DEBUG).
To change log levels as a root user, perform the following: To enable debug logging, run the following command: /subsystem=logging/root-logger=ROOT:change-root-log-level(level=DEBUG) To disable debug logging, run the following command: /subsystem=logging/root-logger=ROOT:change-root-log-level(level=INFO)
Changing the log level in Spring Boot 1.5+ can be done with a http-endpoint
Add
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
and than you can use
curl -X "POST" "http://localhost:8080/loggers/de.springbootbuch" \ -H "Content-Type: application/json; charset=utf-8" \ -d $'{ "configuredLevel": "WARN" }'
Where everything beyond /loggers/ is the name of the logger.
If you running this in PCF it get's even better: This is directly supported from their backend.
For Spring Boot 2.1.5+:
First, you need the actuator Plugin:
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
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" }'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With