Repository navigation
Description
CompositeConfiguration.reconfigure() reloads each child with ConfigurationFactory.getInstance().getConfiguration(ctx, name, uri) instead of calling the child's own reconfigure(). Suppose a child was built by the application as a subclass of XmlConfiguration, or by a factory that is not the active one. After a reconfigure, including one triggered by monitorInterval, that child comes back as a plain XmlConfiguration, and the loggers or nodes its class added are gone. A single, non-composite configuration of the same class keeps them, because its overridden reconfigure() is called.
Configuration
Version: 2.26.1, also 2.x at ea28f5a78b, 2.17.2, 2.7, 3.0.0-beta3 and main at 2bb673f650
Operating system: macOS
JDK: OpenJDK 17.0.14
Logs
2.26.1, active configuration after the overlay file was edited and the monitorInterval="1" watcher reloaded it:
PASS composite-monitor initial: config=CompositeConfiguration children=[CustomXmlConfiguration, CustomXmlConfiguration] loggers=[, from.setup, from.base, from.xml] from.xml.level=DEBUG
FAIL composite-monitor after file touch: from.setup.trace=false config=CompositeConfiguration children=[XmlConfiguration, XmlConfiguration] loggers=[, from.base, from.xml] from.xml.level=WARN
Control, a single configuration of the same class, 2.26.1:
PASS single after onChange(config): config=CustomXmlConfiguration children=[CustomXmlConfiguration] loggers=[, from.setup, from.base, programmatic]
Reproduction
base.xml:
<Configuration status="WARN" name="base" monitorInterval="1">
<Appenders>
<Console name="Out"><PatternLayout pattern="%c %p %m%n"/></Console>
</Appenders>
<Loggers>
<Logger name="from.base" level="info"/>
<Root level="info"><AppenderRef ref="Out"/></Root>
</Loggers>
</Configuration>overlay.xml:
<Configuration status="WARN" name="overlay" monitorInterval="1">
<Loggers>
<Logger name="from.xml" level="debug"/>
</Loggers>
</Configuration>public class CustomXmlConfiguration extends XmlConfiguration {
public CustomXmlConfiguration(LoggerContext ctx, ConfigurationSource source) {
super(ctx, source);
}
@Override
public void setup() {
super.setup();
for (Node loggers : getRootNode().getChildren()) {
if ("Loggers".equals(loggers.getName())) {
Node template = loggers.getChildren().get(0);
Node node = new Node(loggers, "Logger", template.getType());
node.getAttributes().put("name", "from.setup");
node.getAttributes().put("level", "trace");
loggers.getChildren().add(node);
}
}
}
@Override
public Configuration reconfigure() {
try {
return new CustomXmlConfiguration(getLoggerContext(), getConfigurationSource().resetInputStream());
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
}File base = new File("base.xml");
File overlay = new File("overlay.xml");
Configuration composite = new CompositeConfiguration(Arrays.asList(
new CustomXmlConfiguration(null, new ConfigurationSource(new FileInputStream(base), base)),
new CustomXmlConfiguration(null, new ConfigurationSource(new FileInputStream(overlay), overlay))));
LoggerContext ctx = Configurator.initialize(Main.class.getClassLoader(), composite);
System.out.println(ctx.getLogger("from.setup").isTraceEnabled());
ctx.onChange((Reconfigurable) ctx.getConfiguration());
System.out.println(ctx.getLogger("from.setup").isTraceEnabled());This prints true, then false. Editing overlay.xml while the context runs, instead of calling onChange, gives the same result once the watcher reloads. Using one CustomXmlConfiguration on its own, instead of the composite, prints true both times.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsTo triage
Activity