Skip to content

Instantly share code, notes, and snippets.

@rsrini7
Created January 8, 2023 11:53
Show Gist options
  • Save rsrini7/ed15c37cf0075b99c705c26bde03c2cf to your computer and use it in GitHub Desktop.
Save rsrini7/ed15c37cf0075b99c705c26bde03c2cf to your computer and use it in GitHub Desktop.
spring actuator and change log level at runtime
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.
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