I'm using embedded Jetty 9, with slf4j.jar in the path. By default, jetty logs tons of information.
I'd like to disable the logging, or at least change the log level to INFO. How can I do this in the program (i.e., without putting some xml configuration file)?
There is no way using straight slf4j to set the Logger level, as slf4j is just a log facade/routing API.
You would need to rely on the underlying logging implementation to set the logging level on the namespace "org.eclipse.jetty" Such as:
If using slf4j-simple.jar, and the SimpleLogger, then you cannot set the level programmatically, only via System properties once the SimpleLogger is initialized, which is very early in the JVM.
If using slf4j-log4j.jar, use the Log4j specific techniques.
org.apache.log4j.LogManager.getLogger("org.eclipse.jetty").setLevel(Level.WARN);
java.util.logging.LoggerFactory.getLogger("org.eclipse.jetty").setLevel(Level.WARNING);
final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger("org.eclipse.jetty");
if (!(logger instanceof ch.qos.logback.classic.Logger)) {
return;
}
ch.qos.logback.classic.Logger logbackLogger = (ch.qos.logback.classic.Logger) logger;
logbackLogger.setLevel(ch.qos.logback.classic.Level.WARN);
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