Scrivio Interview library
DebuggingIntermediate7 min read · updated 12 November 2026

A service logs in the right format locally but in production prints the default Spring Boot format and ignores the logger levels from logback-spring.xml. The production container image is built from the same jar. What would you check?

If the same jar logs correctly locally but uses the default Boot format in production, something in the production environment chooses a different configuration or none: a logging.config property or LOGGING_CONFIG variable, a logback.xml or logback-test.xml from a dependency that wins over logback-spring.xml, <springProfile> blocks whose names do not match the production profile, or a different logging backend taking over the SLF4J provider. I would turn on Logback's status output to see exactly which file was loaded and whether it raised errors.

Why this question is asked

This is a classic production puzzle because the usual suspect, a different build, has been ruled out. The jar is identical, so the difference must come from how it is started or from which of several possible configurations wins at runtime. Interviewers like it because it tests whether we know Boot's logging start-up order well enough to debug it systematically instead of guessing. In this answer, we will first make Logback tell us what it loaded, then go through the likely causes in the order I would check them: explicit configuration overrides, a competing file on the classpath, profile mismatches and a different backend, and finish with how to stop this from reaching production again.

1First, Make Logback Tell Us What It Did

Guessing is slow. Logback keeps an internal status log of every configuration step: which file it found, which appenders it created, and any errors. We can print it in two ways. If we can change the file, debug="true" on the root element prints the status at start-up. Without touching the file, a system property installs a status listener that prints to the console.

Java
# add to the production start command, no rebuild needed
java -Dlogback.statusListenerClass=ch.qos.logback.core.status.OnConsoleStatusListener -jar app.jar
// typical output when a dependency's file wins:
// INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at
// [jar:file:/app/app.jar!/BOOT-INF/lib/legacy-client-3.2.jar!/logback.xml]
// typical output when our file is loaded but a profile block is empty:
// INFO ... - Found resource [logback-spring.xml] ...
// WARN ... - No appenders present in context [default] for logger [ROOT]

The status output usually answers the question in one line, so I would always start here. Exact message wording varies between Logback versions, so read it for the file path rather than for exact text.

2Check 1: An Explicit Override in Production

Spring Boot loads whatever logging.config points to. In production that property can come from places that do not exist locally: an environment variable LOGGING_CONFIG in the deployment manifest, an application-prod.yml, a config server, or a -Dlogging.config option in the container's entry point. If it points to a file that does not exist, start-up fails; if it points to an old file baked into a base image, we get that file's format.

So I would look at the effective environment: the container spec, the start command and, if Actuator is available, the /actuator/env endpoint filtered for logging. Also check whether production sets logging.structured.format.console, which in Boot 3.4 and later replaces the console format with JSON.

3Check 2: A Competing File on the Classpath

Boot searches for the standard names, logback-test.xml and logback.xml, before the -spring variants. So if any dependency jar contains a logback.xml, it is found first and our logback-spring.xml is never read. logback-test.xml is worse: Logback gives it the highest priority, and it should only ever exist under src/test/resources.

Why would this differ locally if the jar is the same? Because locally we often run from the IDE or with mvn spring-boot:run, where our own resources come first on the classpath and tests resources may even be present, while in production the classpath comes from the jar's BOOT-INF/lib order. Listing the jar quickly settles it.

YAML
# look for stray logging files inside the fat jar and its libraries
unzip -l app.jar | grep -E 'logback(-test)?\.xml'
# BOOT-INF/classes/logback-spring.xml
# BOOT-INF/lib/legacy-client-3.2.jar <- check inside this one
unzip -l BOOT-INF/lib/legacy-client-3.2.jar | grep logback
# logback.xml <- found it: it wins over logback-spring.xml

4Check 3: Profile Names That Do Not Match

If our logback-spring.xml puts all its appenders inside <springProfile name="production"> and the cluster runs with SPRING_PROFILES_ACTIVE=prod, none of those blocks apply. Depending on how the file is written, we end up with no appenders, which Boot reports, or only the fallback part of the file. The default-looking output is often Boot's own base configuration from a block like <springProfile name="!production">.

The fix is to log the active profiles at start-up, which Boot already does in its 'The following profiles are active' line, and compare them with the names in the file. Profile expressions such as name="prod | production" can bridge an inconsistent naming history.

5Check 4: Another Backend Took Over

SLF4J is only an API; at runtime it binds to one provider. If a dependency brings log4j-slf4j2-impl or slf4j-simple onto the classpath next to Logback, SLF4J 2 prints a warning that it found multiple providers and picks one. Boot also detects the backend, and an unexpected Log4j2 on the classpath can mean our Logback file is simply never consulted. Running mvn dependency:tree or gradle dependencies and searching for log4j-core, log4j-slf4j and slf4j-simple shows the culprit, which we then exclude.

Step throughDebugging the wrong log format
  1. Print Logback status at start-upOnConsoleStatusListener
  2. logging.config or LOGGING_CONFIG set?
    YesFix the override in the deploymentNoContinue
  3. Other logback.xml or logback-test.xml in jars?
    YesExclude or remove itNoContinue
  4. springProfile names match active profiles?
    YesContinueNoAlign the names
  5. Second SLF4J provider on the classpath?
    YesExclude the extra backendNoLook at levels set elsewhere

5 steps in order. Play them, or step through them one at a time.

6Why the Levels Are Ignored Too

The ignored logger levels follow from the same causes. If another file was loaded, our <logger> elements were never read. If the profile block was skipped, the levels inside it were skipped too. One more cause is specific to levels: Boot applies logging.level.* properties after the file, so a logging.level.com.shop=INFO set in the production environment silently overrides the DEBUG or WARN in our XML. The /actuator/loggers endpoint shows both the configured and the effective level for each logger, which confirms which source won.

7Follow-up questions

How would you make a misconfigured logging setup fail the build instead?

Add a test that starts the application context with the production profile and asserts on the output, for example with Spring Boot's OutputCaptureExtension, checking that a known log line is valid JSON with the expected fields. Add a build rule, such as the Maven Enforcer plugin or a small check on the packaged jar, that fails when logback.xml or logback-test.xml appears in any dependency or in the main resources. And check Logback's status manager in a test: if it holds any error status after start-up, fail.

Why does Logback give logback-test.xml priority?

So that tests can override the production configuration simply by having the file on the test classpath, without any property. The downside is that a logback-test.xml that leaks into a published library jar overrides the configuration of every application using that library, which is why it must never ship.

What if the status output shows our file but with errors?

Then the file was found but parts of it failed, for example an appender class that is missing from the production classpath or a variable that is not defined there. Logback skips the broken element and continues, so the result can look like a default configuration. The status lines name the element and the cause.

8Conclusion

In this answer, we debugged a service that logs correctly locally but uses Boot's default format in production. We started by printing Logback's status to see which file was loaded, then checked for a logging.config or LOGGING_CONFIG override, a logback.xml or logback-test.xml in a dependency jar that wins over logback-spring.xml, <springProfile> names that do not match the active profile, and a second SLF4J provider. The ignored levels follow from the same causes or from logging.level properties set in production, and tests plus a jar check can stop it before release.

What to say in the interviewAbout 90 seconds aloud

Open with

Since the jar is the same, I would look for something that picks a different configuration at runtime. The first thing I do is turn on Logback's status output, either debug=true in the file or -Dlogback.statusListenerClass with the console status listener on the start command, because it prints exactly which file was found and any errors.

Then, if they want more

Then I go through the usual causes. One, an explicit override in production: a logging.config property or LOGGING_CONFIG environment variable in the manifest, a profile-specific properties file or a config server, or logging.structured.format.console set there.

Two, a competing file: Boot looks for logback-test.xml and logback.xml before logback-spring.xml, so a logback.xml inside some dependency jar wins, and logback-test.xml has top priority and should never ship. Locally the classpath order is often different, which is why it looked fine. I check with unzip -l on the jar.

Three, the springProfile blocks: if the file says production and the cluster runs prod, no appenders apply. Four, a different backend: a dependency pulling in log4j-slf4j2-impl or slf4j-simple can take over the SLF4J provider. The ignored levels usually come from the same cause, or from logging.level properties in production, which Boot applies after the file.

To prevent it, I'd add a test that asserts the production log format and a build check that fails on stray logback files.

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 "A service logs in the right format locally but in production prints the default Spring...": https://scrivio-interview-library.netlify.app/java/java-logging/d8d0c6fb0c/