Skip to content

Project information

smartly23 edited this page Jun 6, 2013 · 3 revisions

What it does

This programme converts log4j configuration files from properties format to XML and vice-versa. It also checks validity of properties/XML format and (not comprehensively) compliance with Apache log4j specification (version 1.2).

How to run it

The easiest way is to run the jar package in a java enabled environment. You can download the package here. Complete syntax to run from command line is:

java -jar log4j-convert.jar -i inputFile -o outputFile

where inputFile must be in .xml or .properties format (as the programme will recognize the format based on its suffix). It is possible to ommit outputFile, in which case a default output file will be created in the format inputFileName.suffix, where suffix is .xml if input file was .properties and vice versa. To display help, run the application with -h parameter.

To use library in application clone the source code and use XmlToPropsConverter and PropsToXmlConverter class. Usage:

Converter converter = new XmlToPropsConverter();
converter.convert(inputStream, outputStream);

Converter converter = new PropsToXmlConverter();
converter.convert(inputStream, outputStream);

Supported log4j configuration

Essentially all elements specified in DTD are supported, except some deprecated classes such as CategoryFactory (replaced by LoggerFactory). Deprecated category class with priority parameter will be recognized by the converter for backward compatibility, but will be replaced with logger class and level parameter respectively in the output file.

Custom appender, layout and logger-level classes are supported.

*Please note that it is impossible to recognize whether a wrong level value has been specified or no value was intended, therefore it is necessary to specify null/inherited value for all loggers where implied inheritance is intended.*

Content testing

Programme tests validity of property format (if input is in .properties type) and validity against a [DTD] (https://github.com/rbalent/Log4j-Convert-Configuration/blob/master/log4j.dtd) (if input is in .xml type) respectively. Once these tests pass, the programme will make a series of content-testing. However, there is no Schema for log4j as it is not possible to prescribe content in advance comprehensively (there are e.g. custom classes for numerous settings available). Therefore, the testing is only elementary and should not be relied upon.

Here is a non-exhaustive list of tested content:

generally:
+ whitespaces in places, where it is forbidden
specifically:
+ debug, reset and additivity attributes must be boolean
+ hierarchy-wide threshold must be one of the types specified in log4j API
+ loggers: either custom level or one specified in API
+ appenders: validity of parameters is checked for following predefined appenders:
  • consoleAppender
  • fileAppender
  • rollingFileAppender
  • dailyRollingFileAppender
  • writerAppender
  • asyncAppender
+ for some appender parameters, validity of values is examined, e.g.
  • ImmediateFlush, Append, BufferedIO, LocationInfo parameters must have boolean values
  • BufferSize, MaxBackupIndex, Port, ReconnectionDelay parameters must have integer values
+ validity of parameters for selected appender layouts
+ basic tests for other configurations

Composition

Class Diagram