Logback refresh ignores logger.config and Configurator status, and fails without logback.xml

Author: alvarosanchezCreated Sep 24, 2026Updated Sep 24, 2026
Labelstype: bugrelates-to: logs

Expected Behavior

LoggingSystem.refresh() should configure Logback the same way Logback's own startup does. The exception is a location that only Micronaut can see: logger.config, or logback.configurationFile set in Micronaut configuration. That location should win.

Actual Behaviour

LogbackLoggingSystem.refresh() resets the context and calls LogbackUtils.configure. That method departs from Logback's ContextInitializer.autoConfig in four ways:

  1. Rank and status are ignored. It uses the first ServiceLoader Configurator without sorting by @ConfiguratorRank, and it discards the returned ExecutionStatus.
    • A configurator that returns INVOKE_NEXT_IF_ANY leaves the context with no appenders.
    • A configurator that returns NEUTRAL loses the logback.xml that Logback would apply after it.
  2. Any Configurator service overrides logger.config. Micronaut AOT's StaticLogbackConfiguration is one such service. It always returns DO_NOT_INVOKE_NEXT_IF_ANY (source), and Launch enables it by default for Gradle (aotExtension.rocker.raw#L14) and in Maven's aot-jar.properties (MicronautAot.java#L144), which applies once micronaut.aot.enabled is true.
  3. Otherwise the location defaults to logback.xml (source).
    • In tests, the refresh replaces logback-test.xml with logback.xml.
    • With no logback.xml, startup fails with Resource logback.xml not found.
  4. The management LogbackLoggingSystem reads only logger.config (source). It replaces the context one when the loggers endpoint is enabled. So the #8596 fix does not apply there, and -Dlogback.configurationFile is lost.

The refresh runs at every startup that has any logger.* property. PropertiesLoggingLevelsConfigurer is @Context @Requires(property = "logger") and calls refresh() from its constructor (source). So the effective configuration depends on whether such a property exists.

Steps To Reproduce

A main prints the root logger's appenders after Logback's startup and again after ApplicationContext.run(props). It uses:

  • a stub Configurator in META-INF/services. It either adds a STUB appender and returns DO_NOT_INVOKE_NEXT_IF_ANY or NEUTRAL, or declines with INVOKE_NEXT_IF_ANY;
  • logback.xml (MAIN), logback-test.xml (TEST) and custom-logback.xml (CUSTOM).

Each row is one JVM. lv means logger.levels.foo=INFO. The "Fix" column is a prototype of (a) and (b) below.

# Setup Logback startup Today Fix
1 test + main XML, lv TEST MAIN TEST
2 test XML only, lv TEST fails TEST
3 no XML, lv console fails console
4 stub, logger.config=custom-logback.xml STUB STUB CUSTOM
5 stub declines, main XML, lv MAIN none MAIN
6 stub returns NEUTRAL, main XML, lv STUB+MAIN STUB STUB+MAIN
7 stub, logback.configurationFile in config, lv STUB STUB CUSTOM
8 stub, -Dlogback.configurationFile, lv STUB STUB STUB
9 -Dlogback.configurationFile, lv, loggers endpoint on CUSTOM MAIN not run

Environment Information

  • macOS 26.6.2 on arm64
  • JDK 25.0.4.1
  • logback-classic 1.5.38

Example Application

None. See Steps To Reproduce.

Version

5.3.0-SNAPSHOT: code read on 5.3.x at ea3a123. Reproduced on 5.2.2, which has the same logic.

Proposed fix

LogbackUtils is public, and its configure(ClassLoader, LoggerContext, String) cannot tell an explicit location from the default. Add a method, deprecate the old one, and use it from both LogbackLoggingSystems. That fixes point 4.

  • (a) A Micronaut-only location wins. That is logger.config, or a logback.configurationFile that is not also a JVM system property. Configure from it with DefaultJoranConfigurator, whatever configurators exist. Keep today's lookup, the missing-file error, and the precedence of logback.configurationFile over logger.config.
  • (b) Otherwise, delegate to Logback through the public new ContextInitializer(context).autoConfig(classLoader). It applies rank and status, then Joran (-Dlogback.configurationFile, then logback-test.xml, then logback.xml), then BasicConfigurator.
  • (c) Optionally, and only after measuring it, skip the first startup refresh when there is no Micronaut-only location. Logback has already produced the same result.
    • To keep levels isolated between several contexts in one JVM (as in micronaut-test), mark the context with putObject after every refresh.
    • reset() clears the object map, so the mark must be set again each time.

Compatibility and tests

  • (a) only changes setups that are broken today.

  • (b) makes the refresh match Logback's startup:

    • logback-test.xml survives the refresh;
    • a missing logback.xml no longer fails startup;
    • Joran runs after configurators that return NEUTRAL or INVOKE_NEXT_IF_ANY;
    • the highest rank wins;
    • a missing -Dlogback.configurationFile target falls back as it does in Logback.

    This needs a release note. test-suite-logback depends on today's behaviour: its CustomConfigurator returns NEUTRAL, and its spec forces a refresh "so the XML configuration is ignored". That configurator should return DO_NOT_INVOKE_NEXT_IF_ANY.

  • Tests: turn the table into specs.

    • The configurator cases can use a fresh LoggerContext and a class loader that holds the service entry.
    • The XML-lookup cases need their own module, because Joran resolves files through its own class loader.
    • For (c), use two contexts in one JVM with different logger.levels.

How this was found

This came up while profiling micronaut-runner on its benchmark-large sample. Runner's planned build-time configurator (linked under Related) would have to work around points 1 and 2.

Method: Runner JARs, micronaut-context 5.1.15 (same code), JDK 25.0.4.1. Readiness is the first HTTP 200 on /hello. Variants were interleaved at random and paired per round. Figures are medians of paired differences, with bootstrap 95% CIs.

Replacing Joran with a prototype of that configurator that also precompiled the pattern layout saved:

Uncached JDK AOT cache
No logger.* property (n=60) 28.0 ms 11.2 ms
A logger.levels property (n=20) 33.1 ms 18.3 ms

The configurator alone, without the precompiled layout, saved 16.5 ms uncached and 8.2 ms cached in the first row (n=60); the second row was not measured for it. Every 95% CI excludes 0. The difference between the table's two rows, which come from the same prototype, suggests the second Joran pass costs roughly 5 ms uncached and 7 ms cached. This is an estimate across sessions, not a measurement of (c).

Related

  • #8596 and #9009, #8650 and #8674, #8918 and #9859.
  • micronaut-projects/micronaut-aot#512: with that fix, AOT's configurator runs DefaultJoranConfigurator itself when logback.configurationFile is set, so it does not depend on this issue. (a) is what stops it shadowing logger.config after a refresh (rows 4 and 7).
  • micronaut-projects/micronaut-gradle-plugin#1380: its generated wrapper runs Joran itself instead of returning INVOKE_NEXT_IF_ANY, so it does not need (b). Until (a) ships, a logger.config set in Micronaut configuration is ignored after a refresh, as it is with AOT's configurator.
  • https://github.com/alvarosanchez/micronaut-runner/issues/152: Runner's planned configurator.
  • https://github.com/alvarosanchez/micronaut-runner/issues/135: Runner packages AOT's optimized JAR, including StaticLogbackConfiguration.

Source: micronaut-projects/micronaut-core