1

When the configuration is made from source code, I need a way to see what was configured without debugging the Java code. I would like to see the current configuration as an XML (similar to log4j2.xml file).

<?xml version="1.0" ?>
<Configuration>
    <Appenders>
       <RollingFile name ....
</Configuration>

I am able to see the XML string when working with ConfigurationBuilder.writeXmlConfiguration/toXmlConfiguration methods. From what I understand this is only available only when using the builder.

From time to time I change different values in the configuration using code like this:

final LoggerContext ctx = (LoggerContext) LogManager.getContext(false);
final Configuration config = ctx.getConfiguration();
...

Is there something like: config.toXML()?

I am thinking to do a small class that we can use to achieve this feature, but first, I want to make sure there is no other possibility.

  • Retrieving the original configuration from instantiated components is not trivial. E.g. retrieving the `append` property of an appender requires reflection (see [test source code](https://github.com/apache/logging-log4j2/blob/4c6ef3582460d5fce758a0eaecc1889a99274880/log4j-1.2-api/src/test/java/org/apache/log4j/config/AbstractLog4j1ConfigurationTest.java#L304)). – Piotr P. Karwasz Feb 15 '22 at 07:15

0 Answers0