[
https://issues.apache.org/jira/browse/LOG4J2-1313?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15480877#comment-15480877
]
Remko Popma edited comment on LOG4J2-1313 at 9/11/16 3:19 AM:
--------------------------------------------------------------
The current logic in
[PluginValueVisitor|https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/visitors/PluginValueVisitor.java#L39]
is
{code}
final String rawValue = Strings.isNotEmpty(node.getValue()) // check if null or
""
? node.getValue()
: removeAttributeValue(node.getAttributes(), "value"); // remove the
property altogether
{code}
So, if there is no value, the property is removed.
As Leon indicated, this means that when the property is defined as {{<Property
name="additionalProp"></Property>}}, references like $\{sys:additionalProp\}
don't get resolved and remain as literal $\{sys:additionalProp\}.
I've committed a failing test demonstrating the issue.
(org.apache.logging.log4j.core.config.PropertyTest)
I tried to stop removing the attributes if the value is empty. Depending on the
return value I get different incorrect results:
{code}
<Properties>
<Property name="elementKey">elementValue</Property>
<Property name="emptyElementKey"></Property>
<Property name="attributeKey" value="attributeValue" />
<Property name="attributeWithEmptyElementKey"
value="attributeValue2"></Property>
<Property name="bothElementAndAttributeKey"
value="attributeValue3">elementValue3</Property>
--------
// option 1: replace "" values with null
final String rawValue = Strings.isBlank(node.getValue()) ? null :
node.getValue();
Test fails like this:
Expected
:1=elementValue,2=,3=attributeValue,4=attributeValue2,5=attributeValue3,m=msg
Actual
:1=elementValue,2=${sys:emptyElementKey},3=${sys:attributeKey},4=${sys:attributeWithEmptyElementKey},5=elementValue3,m=msg
---------------
// option 2: allow "" attributes
final String rawValue = node.getValue();
Test fails like this:
Expected
:1=elementValue,2=,3=attributeValue,4=attributeValue2,5=attributeValue3,m=msg
Actual :1=elementValue,2=,3=,4=,5=elementValue3,m=msg
{code}
The second failure is a more promising avenue but still has issues. This
requires more plugin-fu than I can command at the moment.
Any plugin expert willing to take a further look?
was (Author: [email protected]):
The current logic in
[PluginValueVisitor|https://github.com/apache/logging-log4j2/blob/master/log4j-core/src/main/java/org/apache/logging/log4j/core/config/plugins/visitors/PluginValueVisitor.java#L39]
is
{code}
final String rawValue = Strings.isNotEmpty(node.getValue()) // check if null or
""
? node.getValue()
: removeAttributeValue(node.getAttributes(), "value"); // remove the
property altogether
{code}
So, if there is no value, the property is removed.
As Leon indicated, this means that when the property is defined as {{<Property
name="additionalProp"></Property>}}, references like $\{sys:additionalProp\}
don't get resolved and remain as literal $\{sys:additionalProp\}.
I've committed a failing test demonstrating the issue.
(org.apache.logging.log4j.core.config.PropertyTest)
I tried to stop removing the attributes if the value is empty. Depending on the
return value I get different incorrect results:
{code}
// option 1: replace "" values with null
final String rawValue = Strings.isBlank(node.getValue()) ? null :
node.getValue();
Test fails like this:
Expected
:1=elementValue,2=,3=attributeValue,4=attributeValue2,5=attributeValue3,m=msg
Actual
:1=elementValue,2=${sys:emptyElementKey},3=${sys:attributeKey},4=${sys:attributeWithEmptyElementKey},5=elementValue3,m=msg
---------------
// option 2: allow "" attributes
final String rawValue = node.getValue();
Test fails like this:
Expected
:1=elementValue,2=,3=attributeValue,4=attributeValue2,5=attributeValue3,m=msg
Actual :1=elementValue,2=,3=,4=,5=elementValue3,m=msg
{code}
The second failure is a more promising avenue but still has issues. This
requires more plugin-fu than I can command at the moment.
Any plugin expert willing to take a further look?
> <Property name="" value="" /> not working
> -----------------------------------------
>
> Key: LOG4J2-1313
> URL: https://issues.apache.org/jira/browse/LOG4J2-1313
> Project: Log4j 2
> Issue Type: Bug
> Affects Versions: 2.5
> Reporter: Philipp Knobel
> Assignee: Remko Popma
> Fix For: 2.7
>
>
> The documentation shows examples of the property tag like this
> ([http://logging.apache.org/log4j/2.x/manual/configuration.html#ConfigurationSyntax]):
> {noformat}
> <Properties>
> <Property name="name1">value</property>
> <Property name="name2" value="value2"/>
> </Properties>
> {noformat}
> When using the later one with the value attribute you'll get on startup this
> error:
> {noformat}
> ERROR Property contains an invalid element or attribute "value"
> {noformat}
> It would be good to have the attribute support working as well, as otherwise
> it might happen that IDE auto formatting is line breaking an attribute. If
> this isn't possible please update the documentation.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]