Spring / Spring Boot
How to change log levels without restart using spring boot actuator?
You can change log levels in a running Spring Boot application without a restart
using the Spring Boot Actuator's /actuator/loggers endpoint.
This allows you to dynamically view and modify logging configurations via a simple HTTP request.
Steps to Implement and Use Dynamic Logging
1. Add the Actuator Dependency
Include the Spring Boot Actuator dependency in your project's
pom.xml (Maven) or build.gradle (Gradle) file.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
2. Expose the Loggers Endpoint
To expose the loggers endpoint, configure
management.endpoints.web.exposure.include
in your application.properties or application.yml file.
3. Change Log Levels at Runtime
Use GET requests to view current logger levels and POST requests to change them.
View current logger levels:
GET http://localhost:8080/actuator/loggers
Change a specific logger level:
POST /actuator/loggers/{name}
{
"configuredLevel": "DEBUG"
}
Setting configuredLevel to null resets the logger to its default level.
Important Considerations
- Security: Secure Actuator endpoints, especially in production, due to the sensitive nature of the information and control they provide.
- Persistence: Changes made via Actuator are temporary and will be lost on application restart.
- Centralized Management: Consider tools like Spring Boot Admin for managing log levels across multiple microservice instances.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
