Re: Configure composite filter for specific logger in Log4j2 via properties file

"Piotr P. Karwasz" <[email protected]>
Newsgroups gmane.comp.jakarta.log4j.user
Message-ID <CAFmygFZA9x-1-Z41=fTv8dTVwXD7s5PH6cS5pSjCkJHyYSSFPw@mail.gmail.com>
Hello Stamatis,

I posted a working solution on SO:

logger.t1.filter.M.type = Filters
logger.t1.filter.M.f1.type = RegexFilter
logger.t1.filter.M.f1.regex = .*SQL.*
logger.t1.filter.M.f1.onMatch = NEUTRAL
logger.t1.filter.M.f1.onMismatch = DENY
logger.t1.filter.M.f2.type = RegexFilter
logger.t1.filter.M.f2.regex = .*JPQL.*
logger.t1.filter.M.f2.onMatch = NEUTRAL
logger.t1.filter.M.f2.onMismatch = DENY

The problem is caused by two facts:
1. The `LoggerConfig` only accepts a single filter, so you have to
wrap them in a "Filters" element,
2. A `Properties` class is a `Hashtable`, so the order of the keys is random.

I believe both of them to be bugs of `PropertiesConfigurationBuilder`:
1. I interpret the "filter" prefix in the properties configuration as
an implicit "Filters" component. `addFiltersToComponent` should wrap
the filters in a "Filters" component if more than one is defined.
2. `PropertiesUtil#partitionOnCommonPrefixes` should probably return a
`TreeMap` instead of a `HashMap` to impose a deterministic order on
the filters (and other components that use this function).

You should open a JIRA ticket for this problem and since you
apparently have a PR in progress, submit your test case and a solution
as PR.

Best wishes,
Piotr

On Sat, 2 Apr 2022 at 18:44, Stamatis Zampetakis <[email protected]> wrote:
>
> Hi all,
>
> After many unsuccessful attempts to configure a composite filter for a
> specified logger [1] using the property syntax, I posted the following
> question on stackoverflow [2].
>
> In [1], I tried to create a unit test simulating what I would like to
> achieve but didn't manage to make it work yet. I searched in the code to
> find examples of how this can be done but couldn't find any.
>
> Any feedback would be much appreciated!
>
> Best,
> Stamatis
>
> [1]
> https://github.com/zabetak/logging-log4j2/commit/a9944885100db42f7e3ba1b3ff81d59b743d0ab7
> [2]
> https://stackoverflow.com/questions/71719354/configure-composite-filter-for-specific-logger-in-log4j2-via-properties-file
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.