org.slf4j.helpers.NOPLoggerFactory Java Examples

The following examples show how to use org.slf4j.helpers.NOPLoggerFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AetherUtil.java    From buck with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source File: LoggingDependencyTest.java    From matrix-java-sdk with GNU Affero General Public License v3.0 5 votes vote down vote up
@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");
}
 
Example #3
Source File: JsonixPlugin.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@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.");
	}
}
 
Example #4
Source File: Slf4jClassloadingTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #5
Source File: Slf4jLogFactory.java    From jboot with Apache License 2.0 4 votes vote down vote up
public Slf4jLogFactory() {
    this.useJdkLogger = LoggerFactory.getILoggerFactory() instanceof NOPLoggerFactory;
}
 
Example #6
Source File: Slf4JLoggerFactory.java    From micrometer with Apache License 2.0 4 votes vote down vote up
private Slf4JLoggerFactory() {
    if (LoggerFactory.getILoggerFactory() instanceof NOPLoggerFactory) {
        throw new NoClassDefFoundError("NOPLoggerFactory not supported");
    }
}
 
Example #7
Source File: InternalServerError.java    From flow with Apache License 2.0 4 votes vote down vote up
/**
 * 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());
}