Created
January 8, 2023 11:53
-
-
Save rsrini7/ed15c37cf0075b99c705c26bde03c2cf to your computer and use it in GitHub Desktop.
spring actuator and change log level at runtime
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
To use the Spring Actuator loggers endpoint in a traditional Spring application (i.e., one that does not use Spring Boot), you will need to do the following: | |
Add the spring-actuator dependency to your application. | |
Enable the loggers endpoint by adding the management.endpoint.loggers.enabled property to your application.properties file and setting it to true. | |
Configure the LoggersMvcEndpoint bean in your application context. This can be done by creating a configuration class that implements the ManagementConfigurer interface and overrides the configure method. | |
For example: | |
Copy code | |
@Configuration | |
public class ManagementConfig implements ManagementConfigurer { | |
@Override | |
public void configure(ManagementServerProperties management) { | |
management.setSecurity(false); | |
} | |
@Bean | |
public LoggersMvcEndpoint loggersMvcEndpoint(Logger logger) { | |
return new LoggersMvcEndpoint(logger); | |
} | |
} | |
In this example, the configuration class ManagementConfig implements the ManagementConfigurer interface and overrides the configure method to disable security for the management endpoints. It also creates a LoggersMvcEndpoint bean that can be used to access the loggers endpoint. | |
You can then make a POST request to the /actuator/loggers/{loggerName} endpoint to change the logging level at runtime, as described in my previous responses. | |
I hope this helps! Let me know if you have any other questions. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://betoneful.com/tech/spring-actuator-without-spring-boot/ | |
-> https://gitlab.com/embuc/actuator-spring-traditional | |
https://itecnote.com/tecnote/java-spring-boot-actuator-without-spring-boot/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment