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?
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.
Enumeration appenders = logger. getAllAppenders(); . . . fileBackupIndex = rollingFileAppender. getMaxBackupIndex();
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.
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.
For property based configuration you just simply take the package name without any wildcards. Should work with XML too :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With