You can do it even at runtime 🙂
Spring Boot provides a loggers actuator endpoint for viewing and changing log levels at runtime. What do I need?
Add the Spring Boot Starter Actuator to you pom.xml or build.gradle
org.springframework.boot:spring-boot-starter-actuator
Expose at least the loggers endpoint in your application.properties
management.endpoints.web.exposure.include=loggers
When exposed, you get all loggers details with /loggers:
[code]
curl http://127.0.0.1:8080/actuator/loggers | jq
{
"levels": ["OFF", "ERROR", "WARN", "INFO", "DEBUG", "TRACE"],
"loggers": {
"ROOT": {"configuredLevel": "INFO", "effectiveLevel": "INFO" },
"de": {"configuredLevel": null, "effectiveLevel": "INFO" },
"de.claudioaltamura": {"configuredLevel": null, "effectiveLevel": "INFO"}
}
}
[/code]
For changing a specific logger level at runtime, execute a POST request:
[code]
curl -i -X POST -H ‚Content-Type: application/json‘ -d ‚{"configuredLevel": "DEBUG"}‘ "http://localhost:8080/actuator/loggers/de.claudioaltamura"
HTTP/1.1 204
[/code]
Try it out, here is my github project for this article.