Improve support for alternative Log4j 2 configuration file formats

This commit adds support for configuring Log4j 2 with YAML. It also
improves the existing support for configuring Log4j 2 with JSON.

Previously, Log4J2LoggingSystem returned a hard-coded list of standard
config locations that includes both JSON and XML file suffixes. Log4j 
2’s support for JSON configuration files requires Jackson’s ObjectMapper
to be on the classpath so, in its absence, the standard config locations
were incorrect.

This commit updates Log4J2LoggingSystem to return an array of standard
config locations based on what’s on the classpath. It also updates the
documentation to describe the additional dependencies that are required
to enable YAML or JSON-based configuration.

Closes gh-2239
This commit is contained in:
Andy Wilkinson
2015-01-22 15:06:20 +00:00
parent f0421801fb
commit ea7b5c6e3c
4 changed files with 100 additions and 5 deletions

View File

@@ -1241,6 +1241,18 @@ samples for more detail and to see it in action.
[[howto-configure-log4j-for-logging-yaml-or-json-config]]
==== Use YAML or JSON to configure Log4j 2
In addition to its default XML configuration format, Log4j 2 also supports YAML and JSON
configuration files. To configure Log4j 2 to use an alternative configuration file format
all you need to do is add an appropriate dependency to the classpath. To use YAML, add a
dependency on `com.fasterxml.jackson.dataformat:jackson-dataformat-yaml` and Log4j 2 will
look for configuration files names `log4j2.yaml` or `log4j2.yml`. To use JSON, add a
dependency on `com.fasterxml.jackson.core:jackson-databind` and Log4j 2 will look for
configuration files named `log4j2.json` or `log4j2.jsn`
[[howto-data-access]]
== Data Access