You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@logging.apache.org by "Oliver Limberg (Jira)" <ji...@apache.org> on 2020/09/21 11:18:00 UTC

[jira] [Updated] (LOG4J2-2931) Configuring CompositeFilter via properties will generate error due to invalid arguments

     [ https://issues.apache.org/jira/browse/LOG4J2-2931?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Oliver Limberg updated LOG4J2-2931:
-----------------------------------
    Description: 
The attached test will produce the following errors:

 
{noformat}
ERROR filters contains invalid attributes "onMatch", "onMismatch"
ERROR filters contains invalid attributes "onMatch", "onMismatch"
{noformat}
When the configuration is built, using DefaultConfigurationBuilder, filters are always built using the class DefaultFilterComponentBuilder.
 The constructor will always add the two attributes 'onMatch' and 'onMismatch'.
 However, the createFilters method (annotated with PluginFactory) of CompositeFilter, does not specify the two attributes, so they remain in the list of node attributes in PluginBuilder and when calling checkForRemainingAttributes, the error statements are generated.

A simple solution could be to change the signature of createFilters to include those two attributes. The constructor of the CompositeFilter could stay untouched.
{code:java}
@PluginFactory
public static CompositeFilter createFilters(@PluginElement("Filters") final Filter[] filters,
                                            @PluginAttribute("onMatch") final Result match,
                                            @PluginAttribute("onMismatch") final Result mismatch) {
    return new CompositeFilter(filters);
}{code}
This solution would required to make a minor change in addFilter of class AbstractFilterable and its test class.
 Another solution would be to modify the DefaultFilterComponentBuilder or even use DefaultCompositeFilterComponentBuilder when applicable in DefaultConfigurationBuilder.

  was:
The attached filter will produce the following errors:

 
{noformat}
ERROR filters contains invalid attributes "onMatch", "onMismatch"
ERROR filters contains invalid attributes "onMatch", "onMismatch"
{noformat}
When the configuration is built, using DefaultConfigurationBuilder, filters are always built using the class DefaultFilterComponentBuilder.
The constructor will always add the two attributes 'onMatch' and 'onMismatch'.
However, the createFilters method (annotated with PluginFactory) of CompositeFilter, does not specify the two attributes, so they remain in the list of node attributes in PluginBuilder and when calling checkForRemainingAttributes, the error statements are generated.



A simple solution could be to change the signature of createFilters to include those two attributes. The constructor of the CompositeFilter could stay untouched.
{code:java}
@PluginFactory
public static CompositeFilter createFilters(@PluginElement("Filters") final Filter[] filters,
                                            @PluginAttribute("onMatch") final Result match,
                                            @PluginAttribute("onMismatch") final Result mismatch) {
    return new CompositeFilter(filters);
}{code}
This solution would required to make a minor change in addFilter of class AbstractFilterable and its test class.
Another solution would be to modify the DefaultFilterComponentBuilder or even use DefaultCompositeFilterComponentBuilder when applicable in DefaultConfigurationBuilder.


> Configuring CompositeFilter via properties will generate error due to invalid arguments
> ---------------------------------------------------------------------------------------
>
>                 Key: LOG4J2-2931
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2931
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: Core
>    Affects Versions: 2.13.3
>            Reporter: Oliver Limberg
>            Priority: Minor
>         Attachments: CompositeFilterPropertiesTest.java, log4j2-composite-filter.properties
>
>
> The attached test will produce the following errors:
>  
> {noformat}
> ERROR filters contains invalid attributes "onMatch", "onMismatch"
> ERROR filters contains invalid attributes "onMatch", "onMismatch"
> {noformat}
> When the configuration is built, using DefaultConfigurationBuilder, filters are always built using the class DefaultFilterComponentBuilder.
>  The constructor will always add the two attributes 'onMatch' and 'onMismatch'.
>  However, the createFilters method (annotated with PluginFactory) of CompositeFilter, does not specify the two attributes, so they remain in the list of node attributes in PluginBuilder and when calling checkForRemainingAttributes, the error statements are generated.
> A simple solution could be to change the signature of createFilters to include those two attributes. The constructor of the CompositeFilter could stay untouched.
> {code:java}
> @PluginFactory
> public static CompositeFilter createFilters(@PluginElement("Filters") final Filter[] filters,
>                                             @PluginAttribute("onMatch") final Result match,
>                                             @PluginAttribute("onMismatch") final Result mismatch) {
>     return new CompositeFilter(filters);
> }{code}
> This solution would required to make a minor change in addFilter of class AbstractFilterable and its test class.
>  Another solution would be to modify the DefaultFilterComponentBuilder or even use DefaultCompositeFilterComponentBuilder when applicable in DefaultConfigurationBuilder.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)