Reputation: 1013
I try to define a default for the variable log4j.encoding within by log4j2.xml:
<Properties>
<Property name="log4j.encoding">ISO-8859-15</Property>
</Properties>
Which I use as a variable that is resolved at runtime:
<PatternLayout charset="$${sys:log4j.encoding}" pattern="%msg%n"/>
This configuration leads to the following error:
main WARN Error while converting string [${sys:log4j.encoding}] to type [class java.nio.charset.Charset]. Using default value [null].
But when I use a non-dynamic variable instead (i.e. ${sys:log4j.encoding}, note the single $), which is evaluated once when the configuration file is loaded, the configuration succeeds.
Is it expected behavior that default values do not work for dynamic variables?
Details: The RollingFile that defines the PatternLayout is used by multiple loggers. The path to the file should be determined everytime one of the loggers is loaded, so that each logger writes to its own file. The character set is secondary, though I would like to understand the error message, as my flawed understanding might mean that changing the output file dynamically might fail, as well.
Upvotes: 1
Views: 1226
Reputation: 9141
The charset attribute does not support a dynamic value. The attribute is immutable and is set when the pattern layout is created. Do you have a need for a single Appender to support multiple charsets? How would that work?
Upvotes: 1