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.
-
Maven
-
Gradle
<plugin>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-converter-config</artifactId>
<version>0.3.0-SNAPSHOT</version>
</plugin>
implementation 'org.apache.logging.log4j:log4j-converter-config:0.3.0-SNAPSHOT'
You can access the main functionality of the library through the ConfigurationConverter.convert() method, as shown in the example below:
Main.java
CLI exampleprivate 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);
}
}
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
Format name | Format id | Parsing support | Writing support |
---|---|---|---|
|
yes |
no |
|
|
yes |
no |
|
|
yes |
yes |
|
|
yes |
yes |
|
|
yes |
yes |
|
|
yes |
no |
|
|
yes |
yes |