I am trying to use properties in a log4j2.yaml. The equivalent XML is this.
<Configuration>
<Properties>
<Property name="log-path">logs</Property>
<Property name="archive">${log-path}/archive</Property>
</Properties>
<Appenders>
. . .
I tried this.
Configutation:
name: Default
properties:
property:
name: log-path
value: "logs"
name: archive
value: ${log-path}/archive
Appenders:
But the properties are not getting picked. For example, the following code creates a ${log-path} folder to store a log file instead of the desired logs folder.
fileName: ${log-path}/rollingfile.log
What am I doing wrong?
If you look at the log4j2.json file you can see that the
property
key has to have a value that is is list of (again) key-value pairs. Translated to YAML this looks like the beginning of this file:(the above was converted using
yaml from-json log4j2.json
, with the command being installed from ruamel.yaml.cmdThere is of course guarantee that this works, as there are multiple ways to convert an XML hierarchy to YAML. But it is not very likely that parsing of YAML and JSON differ.
The expansion of
${}
has to be done after loading the YAML file, by walking the data-structure, and it is unlikely that this is done by matching the original mapping keys in a case-insensitive way.