How to disable pilot programming 9?

I am using embedded Jetty 9 with slf4j.jar in the way. By default, a berth records tons of information.

I would like to disable logging, or at least change the log level to INFO. How can I do this in a program (i.e. without putting some xml configuration file)?

+6
source share
1 answer

It is not possible to use direct slf4j to set the Logger level, since slf4j is only the front facade / log routing API.

To set the logging level in the namespace "org.eclipse.jetty" you will need to rely on the basic implementation of logging, For example:

  • If you use slf4j-simple.jar and SimpleLogger , then you cannot set the level programmatically, only through System Properties after initializing SimpleLogger, which is very early in the JVM.

  • If you are using slf4j-log4j.jar, use the special Log4j methods.

org.apache.log4j.LogManager.getLogger("org.eclipse.jetty").setLevel(Level.WARN); 
  • If you are using slf4j-jdk14.jar, use the java.util.logging methods.
 java.util.logging.LoggerFactory.getLogger("org.eclipse.jetty").setLevel(Level.WARNING); 
  • If you use logback.jar, release slf4j Logger to the log file and set the level.
 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); 
+12
source

All Articles