Video in progress
How do you change the log level for a single package in Spring Boot, and can you do it without a restart?
With the logging.level.<package> property in application.yml. To change it without a restart, you send a POST request to Actuator's /actuator/loggers/<logger> endpoint.
📖 Answer
Through configuration:
logging:
level:
root: INFO
uz.myapp.payment: DEBUG
org.hibernate.SQL: DEBUG
Here the whole application is at INFO, and only the payment package and Hibernate's SQL logs are detailed.
If the problem is happening in prod right now and there's no time to redeploy, use Actuator:
curl -X POST http://localhost:8080/actuator/loggers/uz.myapp.payment \
-H 'Content-Type: application/json' \
-d '{"configuredLevel": "DEBUG"}'
The level changes immediately. After you've caught the problem, send null to return to the previous state: if you forget DEBUG on, the log volume goes up several times over.
Pay attention to two things: the loggers endpoint has to be exposed over HTTP and also protected. And if you have several pods, the request hits only one of them, so you have to send it to each instance separately.
Sign up to mark studied questions and save your progress.