I am using log4j2 to do some logging for a project. My Loggers section in my config looks like this.
<Loggers>
<!-- default logger -->
<Root level="info">
<AppenderRef ref="Console"/>
</Root>
<!-- only log warn/error/fatal for external libs -->
<Logger name="org.cfg4j" level="warn" additivity="false">
<AppenderRef ref="Console"></AppenderRef>
</Logger>
<Logger name="io.netty.util" level="warn" additivity="false">
<AppenderRef ref="Console"></AppenderRef>
</Logger>
</Loggers>
This doesn't seem to be having any effect as far as supressing the DEBUG level messages from io.netty.util
I googled "io.netty.util logging" and came up with this. It looks like there is a way to override the default logger
public abstract class InternalLoggerFactory {
private static volatile InternalLoggerFactory defaultFactory;
static {
final String name = InternalLoggerFactory.class.getName();
InternalLoggerFactory f;
try {
f = new Slf4JLoggerFactory(true);
f.newInstance(name).debug("Using SLF4J as the default logging framework");
defaultFactory = f;
} catch (Throwable t1) {
try {
f = new Log4JLoggerFactory();
f.newInstance(name).debug("Using Log4J as the default logging framework");
} catch (Throwable t2) {
f = new JdkLoggerFactory();
f.newInstance(name).debug("Using java.util.logging as the default logging framework");
}
}
defaultFactory = f;
}
I tried giving this a go, butI ran into a few issues. For one, my IDE (intellij) told me that Log4JLoggerFactory is deprecated. I proceeded, but then found out that the instance did not contain a method called "newInstance".
So, I'm a little confused on how to proceed with this. Is there a way for log4j to supress external libraries DEBUG/INFO level messages in the way that I am thinking?