Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

How can you change a logger's level in a running Spring Boot service without a restart? Describe the Actuator loggers endpoint, Logback scan, and Log4j2 monitorInterval, with one risk of each.

There are three common ways: the Actuator loggers endpoint, where a POST to /actuator/loggers/com.shop with {"configuredLevel": "DEBUG"} changes the level on that one instance; Logback's scan attribute, which reloads the configuration file when it changes; and Log4j2's monitorInterval, which re-reads its configuration periodically. Their risks are an endpoint that must be secured and whose changes are per pod and lost on restart, a reload that can leave a broken or partial configuration, and a reconfiguration that re-creates appenders and file handles; in Kubernetes the file-based options only help with mounted ConfigMaps.

Why this question is asked

Being able to change a log level without restarting is one of the most useful tools during an incident: a restart may clear the very state we are trying to understand, and it takes minutes we do not have. Interviewers ask this to check that we know the mechanisms Spring Boot and the logging libraries offer and, just as importantly, what can go wrong with each. In this answer, we will use the Actuator loggers endpoint step by step, then look at file scanning in Logback and Log4j2, compare the three, and see what changes when the service runs as many pods on Kubernetes.

1A Quick Recap: Where the Level Lives

A logger's level is held in memory by the logging framework. When a Spring Boot application starts, the level comes from the configuration file and from logging.level properties, but after that it is just a field on a logger object, and the framework lets us change it while the application runs. Every mechanism below is a different way of reaching that field: through an HTTP endpoint, or by asking the framework to re-read its file.

2The Actuator Loggers Endpoint

Spring Boot Actuator provides a loggers endpoint. A GET lists every logger with its configured and effective level, and a POST to one logger's URL changes its level. The endpoint must be exposed over HTTP first, because Actuator only exposes health by default.

Java
# application.properties
management.endpoints.web.exposure.include=health,loggers
# Read the current level
curl -s localhost:8080/actuator/loggers/com.shop
# {"configuredLevel":"INFO","effectiveLevel":"INFO"}
# Raise it to DEBUG on this instance
curl -s -X POST localhost:8080/actuator/loggers/com.shop \
-H 'Content-Type: application/json' -d '{"configuredLevel":"DEBUG"}'
# HTTP 204 No Content
# Reset it to the inherited level
curl -s -X POST localhost:8080/actuator/loggers/com.shop \
-H 'Content-Type: application/json' -d '{"configuredLevel":null}'

Behind the endpoint, Boot calls LoggingSystem.setLogLevel, which works the same way for Logback and Log4j2. The change applies immediately, to com.shop and every logger below it that has no level of its own.

But there are two catches. First, this is a powerful endpoint: anyone who can call it can flood the disks, so it must sit behind authentication and authorisation, usually on a separate management port that is not reachable from outside. Second, the change lives only in the memory of the instance that received the request. Other pods are untouched, and a restart brings back the configured level.

3Logback's scan Attribute

Logback can watch its own configuration file and reload it when the file changes. We switch this on in the root element.

XML
<configuration scan="true" scanPeriod="30 seconds">
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder><pattern>%d %-5level %logger{36} - %msg%n</pattern></encoder>
</appender>
<logger name="com.shop" level="INFO"/> <!-- edit to DEBUG, saved file is reloaded within 30 s -->
<root level="WARN"><appender-ref ref="CONSOLE"/></root>
</configuration>

The risk is in the reload itself. A reload resets the logger context and builds it again from the file. If the edited file is not valid XML, recent Logback versions fall back to the last configuration that worked, but a file that parses and is wrong in another way, such as a misspelt appender class, can leave us with a partial configuration: some appenders missing and lines silently lost. A reload also discards levels set through Actuator or logging.level properties, because those were applied on top of the file and are not in it. With logback-spring.xml, check whether your Boot and Logback versions handle the Spring-specific tags correctly during a scan-triggered reload.

4Log4j2's monitorInterval

Log4j2 has the same idea under a different name: monitorInterval on the Configuration element, in seconds. Log4j2 checks the file's modification time at that interval and, if it changed, builds a new configuration and swaps it in.

XML
<Configuration monitorInterval="30">
<Appenders>
<RollingFile name="FILE" fileName="logs/app.log" filePattern="logs/app-%d{yyyy-MM-dd}.log.gz">
<PatternLayout pattern="%d %-5level %logger{36} - %msg%n"/>
<TimeBasedTriggeringPolicy/>
</RollingFile>
</Appenders>
<Loggers>
<Logger name="com.shop" level="INFO"/> <!-- change and save; applied within about 30 s -->
<Root level="WARN"><AppenderRef ref="FILE"/></Root>
</Loggers>
</Configuration>
Three ways to change a level at runtime
MechanismScopeMain risk
Actuator POST /actuator/loggers/{name}one instance, until restartmust be secured; per pod; lost on restart
Logback scan="true"every instance reading that filebad edit leaves partial config; resets in-memory levels
Log4j2 monitorIntervalevery instance reading that filere-creates appenders and file handles

Its specific risk is that a reconfiguration creates new appenders and stops the old ones. For file appenders that means closing and reopening file handles, and for network or async appenders it means draining queues and reconnecting. Under heavy load that can cause a short pause or, with a badly configured appender, a few lost events. Like Logback, it also replaces levels that were set in memory.

5What Changes on Kubernetes

In containers, the configuration file is usually inside the image, and nobody edits files inside a running container. So scan and monitorInterval only help if the file is mounted from a ConfigMap. Even then, Kubernetes updates mounted ConfigMap files with a delay that can be a minute or more, and files mounted with subPath are not updated at all. So file scanning on Kubernetes works, but it is slow and easy to misconfigure.

Actuator works per pod, which raises the follow-up question of how to change all of them at once.

6Follow-up questions

How do you change the level across all 20 pods of a service at once?

Do not rely on calling each pod; a load balancer will send the POST to just one of them. Options are a script or tool that lists the pods and calls each pod's Actuator endpoint directly, a shared configuration source such as Spring Cloud Config with Spring Cloud Bus, where changing logging.level.com.shop and sending a refresh event updates every instance, or a ConfigMap with Spring Cloud Kubernetes reload. Whatever we choose, it should record the change and revert it automatically, because a level raised on 20 pods costs 20 times as much.

Is the Actuator change visible in the GET response?

Yes. After the POST, configuredLevel shows DEBUG for that logger, and child loggers without their own level show DEBUG as their effectiveLevel. That is a quick way to confirm that the change reached the instance we intended.

Which of the three would you use during an incident?

Actuator for a quick change on the affected instance, or through a tool that applies it to every pod with an expiry. File scanning is better suited to environments where configuration files are managed centrally and changes are deliberate, such as VMs with configuration management, than to an urgent change on Kubernetes.

7Conclusion

In this answer, we changed log levels without a restart in three ways. The Actuator loggers endpoint changes one instance immediately through LoggingSystem, but it must be secured and its changes are per pod and lost on restart. Logback's scan and Log4j2's monitorInterval reload the configuration file, with the risks of a partial configuration after a bad edit and of appenders and file handles being re-created, and both reset levels set in memory. On Kubernetes, file scanning only helps with a mounted ConfigMap.

What to say in the interviewAbout 90 seconds aloud

Open with

The quickest way in Spring Boot is the Actuator loggers endpoint. Once loggers is exposed, a GET on /actuator/loggers shows each logger's configured and effective level, and a POST to /actuator/loggers/com.shop with configuredLevel DEBUG changes it immediately through Boot's LoggingSystem; posting null resets it.

Then, if they want more

The risks are that it's a powerful endpoint, so it must be behind authentication on a management port, and that it only changes the instance that got the request, and the change is gone after a restart.

The second option is Logback's scan attribute: with scan true and a scanPeriod of, say, 30 seconds, Logback reloads the file when it changes. The risk is the reload: a bad edit can leave a partial configuration, and it wipes levels set at runtime by Actuator or properties.

The third is Log4j2's monitorInterval, which re-reads the configuration every so many seconds. Its risk is that a reconfiguration creates new appenders and closes the old ones, so file handles and connections are reopened, which can cause a hiccup under load.

On Kubernetes, the files are usually inside the image, so scanning only helps with a ConfigMap mount, and those updates are delayed. To change all pods at once, I'd use a tool that calls each pod or a shared config source with a refresh, with an automatic revert.

About this answer

Last updated
12 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "How can you change a logger's level in a running Spring Boot service without a restart?...": https://scrivio-interview-library.netlify.app/java/java-logging/ac6d150b5f/