类org.slf4j.helpers.NOPLoggerFactory源码实例Demo

下面列出了怎么用org.slf4j.helpers.NOPLoggerFactory的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: buck   文件: AetherUtil.java
public static ServiceLocator initServiceLocator() {
  DefaultServiceLocator locator = MavenRepositorySystemUtils.newServiceLocator();
  locator.setErrorHandler(
      new DefaultServiceLocator.ErrorHandler() {
        @Override
        public void serviceCreationFailed(Class<?> type, Class<?> impl, Throwable exception) {
          throw new RuntimeException(
              String.format(
                  "Failed to initialize service %s, implemented by %s: %s",
                  type.getName(), impl.getName(), exception.getMessage()),
              exception);
        }
      });
  locator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
  locator.addService(TransporterFactory.class, HttpTransporterFactory.class);
  locator.addService(TransporterFactory.class, FileTransporterFactory.class);
  // Use a no-op logger. Leaving this out would introduce a runtime dependency on log4j
  locator.addService(ILoggerFactory.class, NOPLoggerFactory.class);
  // Also requires log4j
  //    locator.addService(ILoggerFactory.class, Log4jLoggerFactory.class);
  return locator;
}
 
源代码2 项目: matrix-java-sdk   文件: LoggingDependencyTest.java
@Test
public void login() throws URISyntaxException {
    if (LoggerFactory.getILoggerFactory() instanceof NOPLoggerFactory) {
        Assert.fail("No logging implementation found, using fallback NOP logger");
    }
    Logger logger = LoggerFactory.getLogger("");
    logger.info("If you see this info in the logger, everything is alright");
}
 
源代码3 项目: jsonix-schema-compiler   文件: JsonixPlugin.java
@Override
public void onActivated(Options opts) throws BadCommandLineException {
	final ILoggerFactory iLoggerFactory = LoggerFactory.getILoggerFactory();
	if (iLoggerFactory instanceof NOPLoggerFactory) {
		System.err
				.println("You seem to be using the NOP provider of the SLF4j logging facade. "
						+ "With this configuration, log messages will be completely suppressed. "
						+ "Please consider adding a SLF4j provider (for instance slf4j-simple) to enable logging.");
	}
}
 
@Test
public void shouldNotUseNopLoggerFactory() {
  ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();

  // verify that a SLF4J backend is used which is not the NOP logger
  assertFalse("Should not use NOPLoggerFactory", loggerFactory instanceof NOPLoggerFactory);

  // should either use slf4j-jdk14 or slf4j-jboss-logmanager
  String loggerFactoryClassName = loggerFactory.getClass().getCanonicalName();
  assertTrue("Should use slf4j-jdk14 or slf4j-jboss-logmanager",
      JDK14_LOGGER_FACTORY.equals(loggerFactoryClassName) || JBOSS_SLF4J_LOGGER_FACTORY.equals(loggerFactoryClassName));
}
 
源代码5 项目: jboot   文件: Slf4jLogFactory.java
public Slf4jLogFactory() {
    this.useJdkLogger = LoggerFactory.getILoggerFactory() instanceof NOPLoggerFactory;
}
 
源代码6 项目: micrometer   文件: Slf4JLoggerFactory.java
private Slf4JLoggerFactory() {
    if (LoggerFactory.getILoggerFactory() instanceof NOPLoggerFactory) {
        throw new NoClassDefFoundError("NOPLoggerFactory not supported");
    }
}
 
源代码7 项目: flow   文件: InternalServerError.java
/**
 * Returns {@code true} if there is a logging binding available for SLF4J.
 *
 * @return {@code true} if there is a SLF4J logging binding
 */
protected boolean hasLogBinding() {
    ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
    return loggerFactory != null
            && !NOPLoggerFactory.class.equals(loggerFactory.getClass());
}