I have an app that uses various dependencies. These dependencies all use a tangled mess of logging frameworks. Since I do not want any library to ever do any kind of logging I have a small routine that attempts to disable it all. This has worked well for a while, but recently for reasons passing understanding it has stopped working for Undertow. Now when the app starts up it prints this:
13:35:14.001 WARN UT005060: Predicate max-content-size[5] uses old style square braces to define predicates, which will be removed in a future release. predicate[value] should be changed to predicate(value) - undertow.parseExpression
13:35:14.046 INFO XNIO version 3.3.8.Final - xnio.<clinit>
13:35:14.059 INFO XNIO NIO Implementation Version 3.3.8.Final - nio.<clinit>
The code I use to disable logging is as follows:
static {
// disables java.util.logging
java.util.logging.LogManager.getLogManager().reset();
// disables log4j
org.apache.log4j.LogManager.getRootLogger().setLevel(org.apache.log4j.Level.OFF);
System.setProperty("org.apache.logging.log4j.simplelog.StatusLogger.level", org.apache.log4j.Level.OFF.toString());
// Disables spymemcached
System.setProperty("net.spy.log.LoggerImpl", "net.spy.memcached.compat.log.SunLogger");
java.util.logging.Logger.getLogger("net.spy.memcached").setLevel(java.util.logging.Level.OFF);
// slf4j has been disabled using the nop-logger in the dependencies
}
Google wasn't much help. I found a post Turn off java.util.logging for a specific package programmatically and attempted to use it but got nowhere. The spurious XNIO messages still pop up.
I want to disable all logging frameworks programmatically, I specifically do not want to pollute my codebase with config files all over the place.
Something I tried that didn't work:
org.apache.log4j.LogManager.getLogger("org.xnio").setLevel(org.apache.log4j.Level.OFF);
org.apache.log4j.LogManager.getLogger("org.jboss").setLevel(org.apache.log4j.Level.OFF);
org.apache.log4j.LogManager.shutdown();
java.util.logging.Logger.getLogger("org.jboss").setLevel(java.util.logging.Level.OFF);
java.util.logging.Logger.getLogger("org.xnio").setLevel(java.util.logging.Level.OFF);
org.apache.log4j.Logger.getLogger("org.jboss").setLevel(org.apache.log4j.Level.OFF);
org.apache.log4j.Logger.getLogger("org.xnio").setLevel(org.apache.log4j.Level.OFF);
org.apache.log4j.Logger.getRootLogger().removeAllAppenders();
org.apache.log4j.Logger.getRootLogger().addAppender(new NullAppender());