Sub topic 13
Changing log levels at runtime with Actuator
Sometimes a production bug only shows up in DEBUG output, and restarting the application to get that output would destroy the state you want to inspect. Spring Boot Actuator has a loggers endpoint that reads and changes log levels while the application runs. This chapter shows how to use it and where it can go wrong.
This chapter assumes you know how to set levels with logging.level.* properties, how the SLF4J and Logback stack fits together, and the basics of HTTP and curl.
What the loggers endpoint does
Actuator is Spring Boot's production-monitoring module. Each feature is an endpoint, and loggers is the one for logging. Behind it is Spring Boot's LoggingSystem abstraction, which wraps the real backend (Logback by default, or Log4j2). The endpoint asks LoggingSystem for the current levels and tells it to change them. The change is made on the live backend, so it takes effect for the next log call.
Setting it up
Add the Actuator starter (spring-boot-starter-actuator) to your build. By default only health is exposed over HTTP, so you must expose loggers yourself:
management.endpoints.web.exposure.include=health,loggers
# Spring Boot 3.4 and later
logging.structured.format.console=ecsThe second line is unrelated to this endpoint. It switches console output to JSON, which the structured logging chapter covers. Remove it if you want plain text.
If the endpoint is missing, the usual cause is the exposure setting. Requests to /actuator/loggers then return 404.
Reading levels
Request /actuator/loggers to list every logger the backend knows about. The response is large, so ask for one logger by name:
curl http://localhost:8080/actuator/loggers/com.example.ordersA typical response:
{"configuredLevel":null,"effectiveLevel":"INFO"}The two fields mean different things:
| Field | Meaning |
|---|---|
| `configuredLevel` | The level set directly on this logger, from properties, XML, or an earlier POST. `null` means none was set. |
| `effectiveLevel` | The level actually used. If `configuredLevel` is `null`, the logger inherits from its nearest configured parent, up to `ROOT`. |
In this example nothing is set on com.example.orders, so it inherits INFO from a parent. When you want to know whether a message will appear, read effectiveLevel.
The full listing also has a levels array (OFF, ERROR, WARN, INFO, DEBUG, TRACE) and a groups section that shows any log groups you defined.
Changing a level
Send a POST with the new level in the body:
curl -X POST http://localhost:8080/actuator/loggers/com.example.orders \
-H 'Content-Type: application/json' \
-d '{"configuredLevel": "DEBUG"}'A successful call returns 204 No Content with an empty body. Check the result with a GET:
{"configuredLevel":"DEBUG","effectiveLevel":"DEBUG"}Child loggers such as com.example.orders.web that have no level of their own now inherit DEBUG, so one call changes the whole package tree.
Resetting
To undo the change, send null as the level:
curl -X POST http://localhost:8080/actuator/loggers/com.example.orders \
-H 'Content-Type: application/json' \
-d '{"configuredLevel": null}'The logger goes back to inheriting from its parent. If your properties file sets logging.level.com.example.orders=debug, a reset returns the logger to inheriting from its parent, not to the property value. The reset clears the logger's own level, and the value from the properties file is not reapplied. Plan for this when you debug a logger that was configured at startup. Note its original level before you change it.
Changing a log group
The endpoint also accepts the name of a log group, not only a logger name. If you defined logging.group.orders=com.example.orders,com.example.billing, then a POST to /actuator/loggers/orders sets the level on both packages in one call.
Changing the root logger
The root logger is addressed as ROOT:
curl -X POST http://localhost:8080/actuator/loggers/ROOT \
-H 'Content-Type: application/json' \
-d '{"configuredLevel": "WARN"}'Avoid setting ROOT to DEBUG or TRACE on a busy production system. It turns on debug output for every library, including the framework, the database driver, and the HTTP client. That can flood your disk and slow the application.
Behavior you should know about
- Changes are temporary. The new level lives in memory. A restart discards it and the application returns to the levels in its configuration files.
- Changes are per instance. If you run five copies behind a load balancer, one POST changes only the copy that received it. Send the request to each instance, or address a specific one directly.
- Typos succeed silently. A POST to
/actuator/loggers/com.exmaple.ordersreturns 204. The backend creates a logger with that name, and no code uses it. After every change, GET the logger and check that your debug lines appear. - Invalid levels fail. A value such as
VERBOSEis not a valid level, and the endpoint answers with a 400 error. Use the uppercase names from thelevelsarray. - It changes logger levels only. You cannot use this endpoint to change appenders, patterns, or file locations. Those need a configuration change and a restart.
Securing the endpoint
The endpoint can raise log volume sharply, and DEBUG output may contain data you would not normally record. Treat it as an administrative feature.
- Expose only what you need. List endpoints by name, as above, instead of
include=*. - Put it behind authentication. With Spring Security on the classpath, Actuator endpoints require a login by default, but
healthis often opened up. Check thatloggersis not open to everyone. - Expect CSRF problems with POST. In an app that uses Spring Security with session cookies, a POST from
curlwith only Basic authentication is rejected with 403 because no CSRF token is sent. For a stateless, token-protected management API, teams usually disable CSRF on the Actuator security chain. Do not disable it for endpoints that browsers reach with cookies. - Move it off the public port. Setting
management.server.port=9090serves Actuator on a separate port that your firewall or ingress does not route to the internet. - Allow reads only, if that is enough. In Spring Boot 3.4 and later,
management.endpoint.loggers.access=read-onlyallows GET and rejects POST. In earlier versions, usemanagement.endpoint.loggers.enabled=falseto switch the endpoint off.
A typical debugging workflow
- GET the logger and note its
configuredLevelandeffectiveLevel. - POST
DEBUGfor the narrowest package that covers the problem, such ascom.example.orders, notROOT. - Reproduce the problem and read the output.
- POST
{"configuredLevel": null}to reset, or POST the original level if one was configured. - GET the logger again to confirm that it is back to normal.
Step 4 matters in practice. A DEBUG level that nobody remembers to undo is a common reason for a log volume spike a week later. Some teams write a reminder in the incident ticket, and some use an automated job that resets levels after a fixed time.
Common errors
| Symptom | Likely cause |
|---|---|
| 404 on `/actuator/loggers` | `loggers` is not in `management.endpoints.web.exposure.include`, or Actuator is on a different port or base path. |
| 401 or 403 | Spring Security is active and the request lacks credentials, a role, or a CSRF token. |
| 400 on POST | The level name is invalid, or the body is not valid JSON. |
| 204 but no new output | Wrong logger name, or the code under test runs on another instance. Also check that the code logs to that logger. |
| Level back to normal after a deploy | The change was in memory only. Put lasting changes in `application.properties`. |
Exercise
Your service has logging.level.com.example.orders=info in application.properties. During an incident you POST {"configuredLevel": "DEBUG"} to /actuator/loggers/com.example.orders, and later POST {"configuredLevel": null}. What is the logger's effectiveLevel after the reset? Then name two reasons that the DEBUG lines might never show up after your first POST, even though it returned 204.
Show answer
After the reset the logger has no level of its own, so it inherits from its nearest configured parent, not from the properties file. If no parent package sets a level, that is the ROOT level (INFO by default in Spring Boot, unless changed). Two reasons that DEBUG lines might not appear: the logger name in the URL was misspelled, so the endpoint created an unrelated logger and returned 204 anyway, or the request reached a different instance than the one handling the traffic. The code might also log through a different logger name than the package you changed.