Repository navigation
Support logback 1.6.x in the logback toolkit layouts - #837
Merged
Merged
Conversation
Logback 1.6.0 removed PatternLayout.defaultConverterMap, which TraceIdPatternLogbackLayout and TraceIdMDCPatternLogbackLayout wrote their conversion words to in a static initializer, so both failed with NoSuchFieldError: defaultConverterMap (apache/skywalking#14120). The layouts now register their conversion words in the logging context's conversion rule registry (CoreConstants.PATTERN_RULE_REGISTRY) when they start, updating it in place as logback does for <conversionRule>. Logback 1.2.x to 1.6.x all read class names from that registry, so the same toolkit artifact keeps working on older logback. Logback 1.5.13 is not supported because of an upstream regression fixed in 1.5.14 (qos-ch/logback#885). The toolkit now compiles against logback 1.6.5, so an API removal fails the build. LogbackVersionCompatibilityTest renders both layouts against logback 1.2.13, 1.3.16, 1.4.14, 1.5.12, 1.5.14, 1.5.38 and 1.6.5, each loaded in an isolated class loader. Add apm-toolkit-logback-scenario, the first plugin test of the logback toolkit and its agent activation. It runs logback 1.2.x to 1.5.x with the released toolkit and checks the trace ID and SkyWalking context rendered by both layouts, including behind an AsyncAppender, through the gRPC log reporter.
Register the SkyWalking conversion words by replacing the context's conversion rule registry with an updated copy, under the context monitor held only for the copy. Layouts starting concurrently, from any class loader, keep each other's words, and logback reads a registry that is never modified afterwards, so no lock is held while logback creates and starts the converters. Nothing is copied once the words are registered. On logback before 1.5.14, which also writes <conversionRule>s to this registry, a rule logback registers at the same time as a layout starts in another thread may be lost; this is documented.
wankai123
approved these changes
Oct 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix apache/skywalking#14120: the logback toolkit layouts fail on logback 1.6.x
Why the bug exists.
TraceIdPatternLogbackLayoutandTraceIdMDCPatternLogbackLayoutregistered%tid/%sw_ctxand%X/%mdcby writing to the staticPatternLayout.defaultConverterMapin a static initializer. Logback 1.6.0 removed that deprecated field (release notes), so the layouts fail withNoSuchFieldError: defaultConverterMap. The module compiled against logback 1.2.3, so the build never noticed.How it is fixed. A shared
AbstractTraceIdPatternLogbackLayoutregisters the conversion words in the logging context's conversion rule registry (CoreConstants.PATTERN_RULE_REGISTRY) when the layout starts. The registry is replaced with an updated copy, never modified in place, and rules that already exist, such as user-defined<conversionRule>s, keep precedence.Behavior changes
%tidalso worked by chance in other encoders, such as a plain<encoder><pattern>, depending on configuration order and reloads. The doc and CHANGES now tell users to declare<conversionRule>s for that, which works on every logback version and also with older toolkit releases on logback 1.6.getDefaultConverterMap()no longer takes precedence on logback ≤1.5.12. Logback 1.6 removed that method, so subclasses now use theregisterConverters(Map)hook.<conversionRule>registered while a toolkit layout starts in another thread can be lost. From 1.5.14, logback keeps XML rules in a separate registry, so this cannot happen there. It is documented in the class javadoc.setContext()already failed with aNullPointerException; it now reports an error and stays stopped.Tests
LogbackVersionCompatibilityTestrenders both layouts against logback 1.2.13, 1.3.16, 1.4.14, 1.5.12, 1.5.14, 1.5.38 and 1.6.5, each in an isolated class loader. With the old layouts it fails only on 1.6.5, with the reportedNoSuchFieldError.TraceIdPatternLogbackLayoutTestcovers:New plugin test
apm-toolkit-logback-scenario, the first one for the logback toolkit and its agent activation, in the JDK 17 workflow. It runs logback 1.2.13, 1.3.16, 1.4.14 and 1.5.38 with the released toolkit 9.7.0, continuing a fixed upstream trace. It asserts the exact trace ID and SkyWalking context rendered by both layouts, including behind anAsyncAppender, through the gRPC log reporter.1.6.5,apm-toolkit.version=9.8.0). Locally, the scenario fails on 1.6.5 with 9.7.0 and passes on all five versions with this change.If this pull request closes/resolves/fixes an existing issue, replace the issue number. Closes [Bug] Logback plugin not compatible with logback >= 1.6.0 skywalking#14120.
Update the
CHANGESlog.