Log4j2 wildcard logger names

Zack picture Zack · Jun 14, 2017 · Viewed 9k times · Source

I am using log4j to do some logging on one of my applications. The Loggers in my config are looking like this.

<Root level="info">
    <AppenderRef ref="Console"/>
</Root>

<Logger name="org.eclipse.jetty.server.Server" level="warn" additivity="false">
    <AppenderRef ref="Console"></AppenderRef>
</Logger>
<Logger name="org.eclipse.jetty.util.log" level="warn" additivity="false">
    <AppenderRef ref="Console"></AppenderRef>
</Logger>
<Logger name="org.eclipse.jetty.server.ServerConnector" level="warn" additivity="false">
    <AppenderRef ref="Console"></AppenderRef>
</Logger>

Basically, I want the "info" level messages from the code that I have written, but I want the external libs to only log if something is a warning or more dire.

This is working as I might expect, but there are a lot of classes under "org.eclipse.jetty"

Is it possible to do something like this?

<Logger name="org.eclipse.jetty.*" level="warn">
    <AppenderRef ref="Console" level="warn"></AppenderRef>
</Logger>

That is, I want everything in the entire package to only warn/error/fatal.

I tried the above and it had no effect. Is there a "wildcard" or something I can use to set up a logger for everything in the package?

Answer

Simon Schrottner picture Simon Schrottner · Jun 14, 2017

For property based configuration you just simply take the package name without any wildcards. Should work with XML too :)