Uploaded image for project: 'Log4j 2'
  1. Log4j 2
  2. LOG4J2-2931

Configuring CompositeFilter via properties will generate error due to invalid arguments

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • 2.13.3
    • None
    • Core
    • None

    Description

      The attached test will produce the following errors:

      ERROR filters contains invalid attributes "onMatch", "onMismatch"
      ERROR filters contains invalid attributes "onMatch", "onMismatch"
      

      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.

      @PluginFactory
      public static CompositeFilter createFilters(@PluginElement("Filters") final Filter[] filters,
                                                  @PluginAttribute("onMatch") final Result match,
                                                  @PluginAttribute("onMismatch") final Result mismatch) {
          return new CompositeFilter(filters);
      }

      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.

      Attachments

        1. CompositeFilterPropertiesTest.java
          2 kB
          Oliver Limberg
        2. log4j2-composite-filter.properties
          2 kB
          Oliver Limberg

        Activity

          People

            pkarwasz Piotr Karwasz
            oklimberg Oliver Limberg
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated: