Change a Service's Log Level at Runtime
Change the log level of a HEAL service at class or root level with Spring Boot Actuator, without Consul keys or a restart.
Changing Log Level with Spring Boot Actuator#
Introduction#
There are consul keys available for updating the log level for each module. If you update the log level using these consul keys, then you need to restart the respective module.
Using the Spring Boot Actuator framework, you can change the log level for a module at the class level or root level without using the consul keys and without restarting the respective module.
Prerequisites#
1. You should build the module on Spring Boot and the module should use Spring Boot Actuator dependency.
2. The module should have a Web server running.
For Example: Tomcat
3. Expose the /logger actuator endpoint to the Web server and enable it. Use the consul key for the same.
In the case of Event Detector, it is
service/eventdetector/management/endpoints/jmx/exposure/include
Procedure#
Follow the below steps to change the Log Level with the Spring Boot Actuator:
1. Check the log level you configured to set at the respective class level using the CURL command or any REST API client.
curl -X GET http://<host>:<port>/<base-path>/loggers/<class-path>
For Example:
curl -X GET http://localhost:8988/measure/loggers/com.heal.module
Expected Output:
{"configuredLevel":"WARN","effectiveLevel":"WARN"}
2. Say, you set the log level at 'WARN' mode. You can change the log level set at the respective class level using the following CURL command or using any REST API client.
curl -i -X POST -H 'Content-Type: application/json' -d '{"configuredLevel": "TRACE"}' http://<host>:<port>/<base-path>/loggers/<class-path>
<host>:<port>: IP Address and port number of the host where you run the module
<base-path>: This should be 'measure'.
For Example:
curl -i -X POST -H 'Content-Type: application/json' -d '{"configuredLevel": "TRACE"}' http://192.0.2.108:8988/measure/loggers/com.heal.module
Expected Output:
HTTP/1.1 204
3. For Supervisor Controller module, use 'https' instead of 'http' in CURL command.
For all other modules, use 'http' in CURL command.
For Example:
curl -kX GET https://localhost:8988/measure/loggers/com.heal.supervisor.controller
curl -k -i -X POST -H 'Content-Type: application/json' -d '{"configuredLevel": "TRACE"}' https://192.0.2.108:8988/measure/loggers/com.heal.supervisor.controller
Class Path for Modules#
Provide one of the following for the respective module in <class-path> in the CURL command.
- Core log level: ROOT
- File log level: com.heal.event.detector
- Audit log level: com.heal.event.detector.scheduler.StatisticsScheduler
- Core log level: ROOT
- File log level: com.heal.action.detector
- Audit log level: com.heal.action.detector.scheduler.StatisticsScheduler
- Core log level: ROOT
- File log level: com.heal.notification.processor
- Audit log level: com.heal.notification.processor.scheduler.StatisticsScheduler
- Core log level: ROOT
- File log level: com.heal.supervisor.controller
- Audit log level: com.heal.supervisor.controller.scheduler.StatisticsScheduler
- Core log level: ROOT
- File log level: com.heal.redis.service
- Audit log level: com.heal.redis.service.monitoring