Scrivio Interview library
LeadershipPrincipal7 min read · updated 12 November 2026

Logging frameworks in Java have changed several times: log4j, commons-logging, SLF4J, Logback, Log4j2, and the Log4Shell incident showed the risk. What long-term rules would you set for logging dependencies?

My rules would be: application code logs only through a facade such as SLF4J and never imports a backend; the whole fleet uses one backend so a patch is one change; every logging library appears in each service's SBOM so we can find vulnerable versions in minutes; risky features such as message lookups stay disabled; and the platform is set up so that the whole fleet can be patched and redeployed within days. Those rules together turn the next Log4Shell from a crisis into a routine upgrade.

Why this question is asked

Java logging has changed hands many times: Log4j 1, Jakarta Commons Logging, java.util.logging, SLF4J with Logback, and Log4j 2. Every change left old jars behind in some services, and in December 2021 Log4Shell (CVE-2021-44228) showed what that costs: a remote code execution flaw in Log4j 2's message lookups, present in a huge number of applications, often several layers deep in dependencies nobody knew about. Interviewers ask this at the most senior level because the answer shows whether we can set rules that survive the next framework change and the next vulnerability. In this answer, we will recap what happened and why it was hard, then go through each rule with the reasoning behind it, and finish with what patching within days really requires.

1A Quick Recap of Log4Shell and Why It Was Hard

Log4j 2 had a feature called lookups: special expressions inside a log message, such as ${java:version}, that Log4j replaced with a value when it formatted the line. One kind of lookup used JNDI, a Java API for looking up objects by name, which can load code from a remote server. Because the lookups were applied to the message itself, any application that logged text received from a user, such as a User-Agent header, could be made to fetch and run an attacker's code just by logging it.

The fix itself was simple: upgrade Log4j 2, through 2.15, 2.16 and finally 2.17.1 as further issues were found, with 2.16 removing message lookups entirely. The hard part was finding where it ran. Many organisations did not know which services contained log4j-core, because it came in transitively through other libraries, sat inside shaded jars, or lived in old services nobody had touched for years. Spring Boot applications using the default Logback backend were not exposed to this particular flaw, which shows the value of knowing exactly which backend each service uses.

2Rule 1: Code Against a Facade, Never a Backend

Application code should only use the SLF4J API: org.slf4j.Logger and LoggerFactory. It should never import classes from Logback, Log4j 2 or another backend. The reason is that the facade is the stable part and the backend is the replaceable part. Over the last twenty years the backends changed several times, while code written against SLF4J kept working through every change. When we need to switch the backend because of a vulnerability, a licence, or performance, a facade turns that into a build change instead of edits in thousands of files.

Java
// Allowed
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// Not allowed in application code (enforced by an architecture test)
import org.apache.logging.log4j.LogManager;
import ch.qos.logback.classic.Logger;
@AnalyzeClasses(packages = "com.acme")
class LoggingRules {
@ArchTest
static final ArchRule onlySlf4j = noClasses()
.should().dependOnClassesThat().resideInAnyPackage("org.apache.logging.log4j..", "ch.qos.logback..")
.because("application code logs through SLF4J only");
}
// Violation: OrderService depends on org.apache.logging.log4j.LogManager -> build fails

The architecture test, written here with ArchUnit, makes the rule automatic.

3Rule 2: One Backend Across the Fleet

I would choose one backend for every service, normally Logback since it is Spring Boot's default, and ban the others through the build. One backend means one version to track, one patch to roll out. It also means bridges are set up consistently: calls to the Log4j 2 API, commons-logging and java.util.logging from libraries are all redirected into SLF4J, so there is exactly one place where log events are formatted.

The build enforces this. The shared parent POM or Gradle convention plugin bans log4j-core, Log4j 1 and duplicate SLF4J providers with a dependency rule, so a library that drags one in fails the build and someone has to decide deliberately.

XML
<!-- Parent POM: maven-enforcer-plugin rule -->
<bannedDependencies>
<excludes>
<exclude>log4j:log4j</exclude> <!-- Log4j 1, end of life -->
<exclude>org.apache.logging.log4j:log4j-core</exclude> <!-- not our backend -->
<exclude>org.slf4j:slf4j-simple</exclude>
<exclude>org.slf4j:slf4j-reload4j</exclude>
</excludes>
</bannedDependencies>
# mvn verify
# [ERROR] Rule 0: BannedDependencies failed with message:
# Found Banned Dependency: org.apache.logging.log4j:log4j-core:jar:2.24.3

4Rule 3: Logging Libraries in Every SBOM

A software bill of materials, an SBOM, lists every library inside a build with its exact version. If every service's build produces one and stores it centrally, the question 'which services contain library X below version Y' becomes a query that takes minutes. Without it, it becomes the multi-day search many companies went through in 2021.

So every build generates a CycloneDX SBOM, CI uploads it to a vulnerability analyser together with the service name and version, and the deployment record says which version runs where. When a new logging CVE is published, the analyser lists the affected services, and the service catalog adds owners and environments. Scanning the final container image as well catches copies of a library hidden in shaded jars or the base image.

Step throughFrom a new logging CVE to a patched fleet
  1. CVE published for a logging library
  2. Query SBOMs for affected versionsminutes, not days
  3. Is the library in our standard backend?
    YesPlatform team bumps the version in the parentNoTeams remove or exclude the stray copy
  4. Automated pull requests to every servicedependency bot opens them
  5. CI builds and tests, pipelines deploy
  6. SBOM query confirms no vulnerable version runstarget: within days

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

5Rule 4: Disable Risky Features

Log4Shell came from a convenience feature that almost nobody needed in production. The general rule is that logging configuration should not evaluate expressions from log content or load remote resources. In concrete terms: message lookups stay disabled (they were removed in Log4j 2.16, but older versions and copies must still be checked), JNDI-based appenders and configuration are not used, and logging configuration is loaded only from files inside the artifact or from trusted configuration, never from a URL that a user can influence. Logback had its own, smaller issue in the same period, CVE-2021-42550, which required an attacker to control the configuration file, so this rule applies to whichever backend we use.

6Rule 5: Be Able to Patch the Whole Fleet Within Days

The previous rules make it possible to know what to patch. This rule makes it possible to actually patch it. It needs a few capabilities that are worth building before the next crisis: every service builds from a shared parent or convention plugin, so a version bump in one place reaches all of them; a dependency bot opens update pull requests automatically; every service has a CI pipeline with enough tests to merge such an update with confidence; and deployment is automated, so 400 services can be released in a day.

The most important part is the long tail. The services that cause trouble in a crisis are the ones nobody has built for two years. I would require every service to build and deploy at least once a month, even with no changes, so the pipeline is known to work. And I would rehearse: once a year, pick a harmless library update and measure how long it takes to reach every production service. That number is the real answer to 'how exposed are we to the next Log4Shell'.

7Follow-up questions

Should we switch from Log4j 2 to Logback because of Log4Shell?

Not necessarily. Log4j 2 was fixed and remains a good backend. The lesson is to have one backend and the ability to patch it quickly. If the fleet is already on Logback because it is Boot's default, staying there is simplest; if it is on Log4j 2, keeping it up to date is fine.

What about libraries that log through their own API?

Bridges handle them. Libraries that call the Log4j 2 API, commons-logging or java.util.logging are redirected to SLF4J by the bridge jars Spring Boot's logging starter includes. The build rules then make sure no second backend sneaks in, so every call ends in the one backend we patch.

8Conclusion

In this answer, we drew rules from the history of Java logging and from Log4Shell. Code logs only through SLF4J, enforced by an architecture test. The fleet uses one backend, enforced by banned dependency rules. Every build produces an SBOM so vulnerable versions are found in minutes, risky features such as message lookups and remote configuration stay off, and shared build parents, dependency bots, tests and automated deployment make it possible to patch every service within days, which we rehearse rather than assume.

What to say in the interviewAbout 80 seconds aloud

Open with

Log4Shell taught me that the fix is usually easy and finding where you are exposed is hard, so my rules are about knowing and moving fast. First, application code logs only through a facade, SLF4J, and never imports Logback or Log4j classes.

Then, if they want more

I enforce that with an ArchUnit test, so switching backend later is a build change. Second, one backend across the fleet, normally Logback because it is Boot's default, with bridges routing other logging APIs into SLF4J and enforcer rules banning log4j-core, Log4j 1 and extra SLF4J providers, so there is one version to patch.

Third, every build produces an SBOM that goes to a central analyser, so when a CVE appears I can list the affected services and owners in minutes, and image scans catch shaded copies.

Fourth, risky features stay off: no message lookups, no JNDI in logging, configuration only from trusted files, and user input logged as structured fields rather than mixed into messages. Fifth, the ability to patch the whole fleet within days: shared build parents, a dependency bot, enough tests to merge confidently, automated deployment, and every service built at least monthly.

I would rehearse that once a year and measure how long a library update takes to reach every service.

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 documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Official documentation
Spring Boot reference
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 "Logging frameworks in Java have changed several times: log4j, commons-logging, SLF4J...": https://scrivio-interview-library.netlify.app/spring-boot/boot-logging/8b41304c80/