Log4j Configuration Converter API

To help users migrate between logging implementations the Log4j Configuration Converter offers a simple API to convert configuration files from one format to another.

Using the API

The API is based on a single ConfigurationConverter interface. To use it, first import the log4j-converter-config artifact to your project.

<plugin>
  <groupId>org.apache.logging.log4j</groupId>
  <artifactId>log4j-converter-config</artifactId>
  <version>0.3.0-SNAPSHOT</version>
</plugin>
xml

You can access the main functionality of the library through the ConfigurationConverter.convert() method, as shown in the example below:

Snippet from a Main.java CLI example
private static void convert(String inputFile, String inputFormat, String outputFile, String outputFormat)
        throws ConfigurationConverterException, IOException {
    Path input = Paths.get(inputFile);
    Path output = Paths.get(outputFile);
    try (InputStream inputStream = Files.newInputStream(input);
         OutputStream outputStream = Files.newOutputStream(output)) {
        ConfigurationConverter converter = ConfigurationConverter.getInstance();
        converter.convert(inputStream, inputFormat, outputStream, outputFormat);
    }
}
java

Supported configuration formats

The configuration converter is extensible by third-parties using the ConfigurationParser and ConfigurationWriter interfaces from the o.a.l.l.converter.config.spi package.

The library provides an out-of-the-box support for the following configuration formats

Table 1. List of supported configuration formats
Format name Format id Parsing support Writing support

Log4j 1 Properties

v1:properties

yes

no

Log4j 1 XML

v1:xml

yes

no

Log4j Core 2 XML

v2:xml

yes

yes

Log4j Core 2 JSON

v2:json

yes

yes

Log4j Core 2 YAML

v2:yaml

yes

yes

Log4j Core 2 Properties

v2:properties

yes

no

Log4j Core 3 Properties

v3:properties

yes

yes