NopeCharon opened a new pull request, #825:
URL: https://github.com/apache/logging-log4cxx/pull/825

   Fixes #195
   
   ## Problem
   
   A properties file can configure an appender and its layout, but not the 
filters attached to the appender. The `PropertyConfigurator` reference says 
filters are only supported by `DOMConfigurator`, so anyone who wants a filter 
has to convert the whole configuration to XML.
   
   ## Change
   
   `PropertyConfigurator` now adds filters to an appender. It uses the same 
syntax as the Log4j 1.2 `PropertyConfigurator`:
   
   ```properties
   log4j.appender.A1.filter.ID=fully.qualified.name.of.filter.class
   log4j.appender.A1.filter.ID.option1=value1
   log4j.appender.A1.filter.ID.optionN=valueN
   ```
   
   - `ID` is a name (without dots) that identifies the filter. The filters are 
added to the appender in ascending (string) order of `ID`. As in Log4j 1.2, 
this means `10` comes before `2`, and the reference documentation says so.
   - The option name is the rest of the key after `ID`, so it can contain dots. 
This allows `MapFilter` keys such as `user.ip`:
     ```properties
     log4j.appender.SIMPLE.filter.1=org.apache.log4j.filter.MapFilter
     log4j.appender.SIMPLE.filter.1.user.ip=127.0.0.1
     log4j.appender.SIMPLE.filter.1.user.name=test
     log4j.appender.SIMPLE.filter.1.Operator=AND
     log4j.appender.SIMPLE.filter.1.AcceptOnMatch=false
     ```
   - The options are set and `activateOptions()` is called through 
`PropertySetter`, in the same way as `DOMConfigurator::parseFilters`.
   - A filter with no class value, or with a class that cannot be created, is 
reported by the existing `OptionConverter::instantiateByKey` error messages and 
is not added.
   - An appender used by more than one logger is still parsed once, so its 
filters are added only once.
   - Filters attached to a `FilterBasedTriggeringPolicy` are still XML only. 
The class description now says this, instead of the old statement that filters 
and rolling policies are not supported.
   
   Documentation:
   - `PropertyConfigurator` class reference: a new section on the filter 
syntax, with an example.
   - Configuration samples: a new "Properties Example 3", the properties 
version of XML Example 4 (a `StringMatchFilter` followed by a `DenyAllFilter`).
   - Filters page: the properties version of the first `MapFilter` example.
   - Change log entry under 2.0.0 new features.
   
   ## Testing
   
   New `PropertyConfiguratorTest` tests:
   - `testAppenderFilters`: a `LevelMatchFilter` (with options) followed by a 
`DenyAllFilter`. Checks the chain and that only the matching event is appended.
   - `testAppenderFilterOrder`: IDs `2` and `10` are added in string order.
   - `testAppenderFilterOptionWithDots`: `MapFilter` option names that contain 
dots.
   - `testAppenderFilterWithoutClass`: options without a class property, and an 
unknown class, add no filter.
   - `testSharedAppenderFilters`: an appender used by two loggers gets its 
filter once.
   
   Without the change in `propertyconfigurator.cpp`, the first four tests fail. 
`testAppenderFilterWithoutClass` checks that a bad entry is ignored, so it 
passes with or without the change.
   
   On Ubuntu 24.04 (GCC 13), the full `ctest` suite passes (70/70). 
`propertyconfiguratortest` also builds and passes with `-DCMAKE_CXX_STANDARD=11 
-DLOG4CXX_CHAR=wchar_t`.
   
   End to end: a program that loads the new "Properties Example 3" file with 
`PropertyConfigurator::configure(File)` writes only the two messages that 
contain "specific", the same as the XML Example 4 output. A program that loads 
the new `MapFilter` example from the filters page drops only the message where 
both MDC values match.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

  • [PR] Support appender filters in... NopeCharon (via GitHub) via notifications

Reply via email to