Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4j2 wildcard logger names

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?

like image 221
Zack Avatar asked Jun 14 '17 17:06

Zack


People also ask

What is logger name log4j2?

The name of log4j2 loggers are case sensitive. Except root logger, all loggers can be obtained through passing their name into LogManager. getLogger() . LoggerContext is a vocal point for Logging system as you may have multiple LoggerContexts inside your application.

How do you get all Appenders in log4j2?

Enumeration appenders = logger. getAllAppenders(); . . . fileBackupIndex = rollingFileAppender. getMaxBackupIndex();

Which is better log4j or log4j2?

Log4j, Logback, and Log4j2 are good logging frameworks that are broadly used. So which one should you use? I recommend using Log4j2 because it's the fastest and most advanced of the three frameworks. Logback is still a good option, if performance is not your highest priority.

Is log4j and log4j2 same?

Community support: Log4j 1. x is not actively maintained, whereas Log4j 2 has an active community where questions are answered, features are added and bugs are fixed. Automatically reload its configuration upon modification without losing log events while reconfiguring.


1 Answers

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

like image 109
Simon Schrottner Avatar answered Oct 22 '22 17:10

Simon Schrottner