Changing logging levels in a running Spring Boot app

How to temporarily change the logging level in a running Spring Boot application through Actuator, Spring Boot Admin, and Axelix: configuration, working with replicas, and restoring the original level.

Sergey CherkasovSergey CherkasovNov 18, 20269 min read

Hello everyone! My name is Sergey Cherkasov, and I am a Developer Advocate in Axelix Labs, working at Axelix project project. It is an open-source product that, among other things, provides the ability to debug the running Spring Boot application.

When investigating an incident, INFO logs are often not enough, DEBUG needs to be temporarily enabled for a specific package or class.

Spring Boot allows the logging level to be changed directly in a running process. There are three ways to do this: send a request to Actuator, use the Spring Boot Admin interface, or manage connected services through Axelix.

Note

We're currently discussing only the Open Source solutions, that can be used free of any charge.

Actuator is usually sufficient for direct management. A centralized interface becomes useful when there are many services and replicas.

Let's compare these approaches using a single example, temporarily enabling DEBUG for the com.example.orderservice package and restoring the previous level after diagnostics.

Changing Logging Level On The Fly. Technical Implementation.

Spring Boot sets the initial logging levels from logging.level.* and the configuration of Logback, Log4j2, or another supported logging system. While the application is running, these levels can be changed through LoggingSystem. The assigned logging level applies to subsequent events and is stored in the process's memory. Configuration files remain unchanged, and the value is usually lost after a restart.

The logging level is stored separately in each instance. A direct Actuator request changes one instance. Spring Boot Admin and Axelix can apply a logger-level change across all registered instances of an application in one operation.

1. Spring Boot Actuator: a direct request to the application

The /actuator/loggers endpoint shows the current logger levels and allows them to be changed while the application is running. This requires spring-boot-starter-actuator to be included in the service and the loggers endpoint to be available over HTTP:

management.endpoints.web.exposure.include=health,loggers

The logging level can then be changed by sending requests to the running application. Actuator has no built-in role-based access control (RBAC) policy for logger operations. You can configure access rules with Spring Security. The requests below assume the management interface accepts bearer tokens.

# Retrieves the explicitly configured and effective logging levels.
curl -H 'Authorization: Bearer <token>' \
  'https://orderservice.example.internal/actuator/loggers/com.example.orderservice'

# Temporarily enables DEBUG for the package.
curl -X POST \
  -H 'Authorization: Bearer <token>' \
  -H 'Content-Type: application/json' \
  -d '{"configuredLevel":"DEBUG"}' \
  'https://orderservice.example.internal/actuator/loggers/com.example.orderservice'

# Clears the explicitly configured level so the logger inherits its parent's level.
curl -X POST \
  -H 'Authorization: Bearer <token>' \
  -H 'Content-Type: application/json' \
  -d '{}' \
  'https://orderservice.example.internal/actuator/loggers/com.example.orderservice'

If INFO is explicitly configured for the logger, the response to GET looks like this:

{
  "configuredLevel": "INFO",
  "effectiveLevel": "INFO"
}

configuredLevel contains the level assigned directly to this logger, while effectiveLevel is the actual level, taking inheritance into account. If the logger inherits its level, the configuredLevel field is absent from the response.

An empty object {} clears the explicitly configured level and makes the logger inherit its parent's level. For example, if the application configured this logger as INFO and its parent is set to WARN, clearing the level after a change to DEBUG leaves the logger at WARN. To restore the application's INFO setting, record the original configuredLevel before changing it and send another POST with that value.

2. Spring Boot Admin: managing instances through a web interface

Spring Boot Admin allows all the same operations to be performed through a web interface: finding com.example.orderservice and selecting DEBUG is enough, without composing a request manually. Spring Boot Admin runs these operations through the Actuator endpoints of the target instances.

Because Spring Boot Admin uses Actuator, reset action triggers the reset to the LoggingSystem default, not the logging level you've confined. In the same example, the logger that was initially in TRACE was reset to INFO, because INFO is the common LoggingSystem default. That may easily surprise you, essentially if the default logging system level is more verbose than the configured one.

To clarify - this is the behavior of Spring Boot Actuator endpoints, Spring Boot Admin here just acts as a proxy, so it inherits the behavior of Spring Boot Actuator endpoints.

A single dashboard allows registered instances to be viewed, loggers to be searched, and their levels to be changed without direct curl requests to the services. This requires deploying and securing an Admin Server, registering applications, and giving it access to their Actuator endpoints. Spring Boot Admin does not include a built-in RBAC policy for logger operations. In case you need RBAC, then you have to add and maintain it yourself.

Apart from that, if somebody will forget to turn the logging level back off to its original value (which is not always possible with "reset" as we saw), the system may flood the system with logs until somebody notices.

A final note here - starting with Spring Boot Admin 4.1.3, an optional MCP module gives AI agents experimental access to the same Actuator logger operations. Once enabled on the Admin Server, agents can list loggers, inspect a logger’s level, and change it on a selected instance. Also note, that by default anyone will have access to MCP Tools in unauthenticated manner.

See the Spring Boot Admin MCP documentation for more information.

3. Axelix: management through the UI and MCP tools

Each managed application needs a thin Spring Boot Starter. The starter supplies the dedicated logger endpoint used by Axelix. Because Axelix works on its own, custom Spring Actuator endpoints (although, we're planning to migrate from them in part to support other ecosystems, like Micronaut or Quarkus or framework-less environments), it is capable to fix all of the gaps of Spring Boot native actuator endpoints.

For example, Axelix Master includes built-in. configurable RBAC. Its default roles all grant access to the logger operations shown here, including changing and resetting a level.

When you reset an individual logger in Axelix, it restores the previous logging level that was effective/configured explicitly, not LoggingSystem default, which is often the desired behavior.

In order to avoid accidentally flooding the system with logs as discussed above, Axelix allows a timer can be set to specify immediately when the previous level should be restored. Once the specified time has elapsed, Axelix resets the level automatically. This reduces the risk of leaving DEBUG enabled after the investigation is complete.

This is especially important for performance considerations as well as cloud bill, since the cloud logs are often analyzed by the cloud provider, such as AWS CloudWatch.

This timer is guaranteed to fire, since the timer to reset log back will run inside the managed application, and thus will fire even if the connection from Axelix Master --> Starter is lost.

Change the level across all instances

One of the other concerns that teams have is that they often have not a single, but many instances of the app running in production/staging environment. For example, hypothetical order-service may run six replicas.

Axelix allows to select the exact instances (the default is "all") where the log level change must take place.

On the Axelix Loggers page, open Instances next to the search field and choose Select all other instances. The instance you opened is already included. Set the logger to DEBUG once to apply the change to all managed replicas. You can also select a subset of replicas from the same list.

Try it with an AI agent

All of the operations that Axelix provides are available for humans via UI, and for AI Agents via embedded MCP server. It is embedded into Axelix Master by default, so installing Axelix Master is sufficient.

Connect an MCP client to Axelix Master and give the agent this prompt:

Please, see the status of the 'payment-processing' job, why it failed?

This is how the typical prompt will look like.

  1. AI Agent will retrieve the log feed of the specific instance of the app, understand that it does not have the logs required
  2. After that, the temporary logger level change will be request, just for the time to debug
  3. The AI Agent will then call the mcp tool for running the scheduled task (which is also possible in Axelix)
  4. And then retrieve the new logs to pinpoint the problem and make necessary code changes, if needed.

Access to MCP server is also covered with RBAC, allowing to control who have access to what operations.

Conclusion

Generally, in Open Source, we can either interact with Spring Boot actuator endpoints directly, or use external tooling, e.g Spring Boot Admin or Axelix.

To finally compare the approaches, lets look at the following table below:

CapabilitySpring Boot ActuatorSpring Boot AdminAxelix
Web UI for loggers-YesYes
AI agent integration via MCP-Experimental, opt-in module since 4.1.3Yes
Access control for logger operations--Built-in RBAC
Dependency in the managed applicationSpring Boot ActuatorSpring Boot Actuator, Admin Client optional with discoverySpring Boot Actuator, Axelix Spring Boot Starter required
Reset an individual loggerClears to logging system defaultClears to logging system defaultRestores the original level
Automatic timer-based reset--Yes
Change a logger across all managed instances in one operation-Yes, via Application scope since 2.2.0Yes, via the UI or bulk API
Important

Worth mentioning that in case of Axelix presence of Axelix Spring Boot starter is necessary, and in case of Spring Boot Admin, the client library of Spring Boot admin is optional.

Hope you found this article helpful. If you're interested in Axelix, you can find the source code over on GitHub.

Have a nice day!