Log4j 2 configuration: XML vs JSON? Log4j 2 configuration: XML vs JSON? json json

Log4j 2 configuration: XML vs JSON?


There is no performance advantage or disadvantage to using XML or JSON. Personally I prefer XML for these two reasons: (but they are not huge problems so of course it is up to you...)

  • JSON configuration requires the Jackson jar files in the classpath, so there's an extra dependency. XML uses the XML parser built in to Java.
  • All examples in the log4j2 manual use XML, not JSON, so you'll need to convert the syntax. If you choose XML you can copy-and-paste from the manual.

I would not recommend programmatic configuration. It is more complex and depends on implementation specifics, which may change in the future. IMHO it will be a bunch of work for little or no benefit.

For the use case you describe, you can use system properties in your configuration so multiple apps can share the same config but log to different locations by varying the property values for each application.


UPDATE:

Log4j2 added an API for programmatic configuration in a later release. This API doesn’t expose implementation details. However it’s mostly suitable for configuring from scratch. If you want to modify an existing configuration you will need to use implementation classes.