Re: Are globs or regular expressions supported in logger names in config files?

Ralph Goers <[email protected]> Thu, 5 Oct 2023 08:07:13 -0700
Newsgroups gmane.comp.jakarta.log4j.user
Message-ID <[email protected]>

> On Oct 5, 2023, at 6:13 AM, Thorsten Schöning <[email protected]> wrote:
> 
> Hi everyone,
> 
> I have many logger names following some naming convention like in the following examples:
> 
> * org.example.unique_phrase.foo
> * org.example.unique_phrase.bar
> * org.example.foo.unique_phrase.bar
> * org.example.bar.unique_phrase.foo
> 
> The goal is to configure one file appender for all packages/logger names containing "unique_phrase". At the same time I would like to keep the possibility for more fine grained configs with possible different appenders for different packages of the above example. The only solution I know of is really configuring all individual (parent) logger names/packages with the same appender. Would be easier if logger names would support some concept of globs or regular expressions, so one might only use something like the following name:
> 
> * org.example.*.unique_phrase.*
> 
> Is something like that possible, either out-of-the-box or possibly some plugin or ...? Thanks!
> 

If this is what you really want then you could create a LoggerNamePatternFilter and configure it like

<Logger name=“org.example” level=“trace”>
   <AppenderRef ref=“patternAppender”>
     <LoggerNamePatternFilter pattern=“org.example.*.unique_phrase.*” onMatch=“NEUTRAL” onMisMatch=“DENY"/>
  </AppenderRef>
</Logger>

Ralph