- Notifications
You must be signed in to change notification settings - Fork 41.6k
Description
Logback refactored the inclusion of configuration snippets in version 1.5.5. (For details see this commit and this comment in logback repo.)
Updating logback from <= 1.5.4 to >= 1.5.5 breaks <springProperty>
when used within an included configuration snippet.
Example
A simple spring boot application using logback.
A prefix for log messages is configured in the environment using <springProperty>
.
logback.xml
<configuration> <include resource="included.xml" optional="false" /> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>${prefix} %msg %n</pattern> </encoder> </appender> <root level="DEBUG"> <appender-ref ref="STDOUT" /> </root> </configuration>
included.xml
<included> <!-- works with 1.5.4, broken with 1.5.5 and 1.5.6 --> <springProperty name="prefix" source="prefix" scope="context" defalultValue="[default prefix]" /> </included>
in application.properties
prefix = [prefix from env]
The expected log output is "[prefix from env] ..." but acutaly is "prefix_IS_UNDEFINED ...".
Cause
Since the refactoring a new instance of JoranConfigurator
is created when an inclusion is processed.
new code in JoranConfigurator
private JoranConfigurator makeAnotherInstance() { JoranConfigurator jc = new JoranConfigurator(); jc.setContext(this.context); return jc; } public void buildModelInterpretationContext() { super.buildModelInterpretationContext(); this.modelInterpretationContext.setConfiguratorSupplier(() -> { return this.makeAnotherInstance(); }); }
The new instance is currently not a SpringBootJoranConfigurator
but a simple JoranConfigurator
that does not know about springs extensions (e.g. <springProperty>
).
Therefore <springProfile>
might be affected as well.
Fix
Overriding buildModelInterpretationContext()
in SpringBootJoranConfigurator
to provide an instance of SpringBootJoranConfigurator
with the same LoggingInitializationContext
.