當前位置: 首頁>>代碼示例>>Java>>正文


Java ILoggerFactory類代碼示例

本文整理匯總了Java中org.slf4j.ILoggerFactory的典型用法代碼示例。如果您正苦於以下問題:Java ILoggerFactory類的具體用法?Java ILoggerFactory怎麽用?Java ILoggerFactory使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ILoggerFactory類屬於org.slf4j包,在下文中一共展示了ILoggerFactory類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: lookUpConfiguredLoggerFactory

import org.slf4j.ILoggerFactory; //導入依賴的package包/類
private Set<Class<? extends ILoggerFactory>> lookUpConfiguredLoggerFactory() {
    final Set<Class<? extends ILoggerFactory>> loggerFactories = new HashSet<>();

    final String configuredLoggerFactory = System.getProperty(ENVIRONMENT_VAR_LOGGER_FACTORY);
    if (StringUtils.isNotBlank(configuredLoggerFactory)) {
        Util.report("Instructed logger factory to use is " + configuredLoggerFactory);
        try {
            final Class clazz = Class.forName(configuredLoggerFactory);
            loggerFactories.add(clazz);
        } catch (final Exception e) {
            Util.report("Could not locate the provided logger factory: " + configuredLoggerFactory + ". Error: " + e.getMessage());
        }
    }

    return loggerFactories;
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:17,代碼來源:CasLoggerFactory.java

示例2: flushLogs

import org.slf4j.ILoggerFactory; //導入依賴的package包/類
private void flushLogs() {
  final long millisToWait = 100;

  LOG.info("Attempting to flush logs and wait {} ...", JavaUtils.durationFromMillis(millisToWait));

  ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
  if (loggerFactory instanceof LoggerContext) {
    LoggerContext context = (LoggerContext) loggerFactory;
    context.stop();
  }

  try {
    Thread.sleep(millisToWait);
  } catch (Exception e) {
    LOG.info("While sleeping for log flush", e);
  }
}
 
開發者ID:PacktPublishing,項目名稱:Mastering-Mesos,代碼行數:18,代碼來源:SingularityAbort.java

示例3: initContext

import org.slf4j.ILoggerFactory; //導入依賴的package包/類
/**
 * Sets references to the LoggerContext. Must be called whenever logging
 * configuration changes between {@link #startCaching()} and {@link #stopAndFlush()}
 */
public static synchronized void initContext() {
	ILoggerFactory iLoggerFactory = LoggerFactory.getILoggerFactory();
	if (!(iLoggerFactory instanceof LoggerContext)) {
		// Not using LogBack, CacheAppender not applicable
		LOGGER.debug("Not using LogBack, aborting CacheLogger");
		loggerContext = null;
		return;
	} else if (!isActive()) {
		LOGGER.error("initContext() cannot be called while isActive() is false");
		return;
	}

	loggerContext = (LoggerContext) iLoggerFactory;
	rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
	disposeOfAppenders();
	detachRootAppenders();
	if (!rootLogger.isAttached(cacheAppender)) {
		rootLogger.addAppender(cacheAppender);
	}
	cacheAppender.setContext(loggerContext);
	cacheAppender.setName("CacheAppender");
	cacheAppender.start();
}
 
開發者ID:DigitalMediaServer,項目名稱:DigitalMediaServer,代碼行數:28,代碼來源:CacheLogger.java

示例4: setContextAndRoot

import org.slf4j.ILoggerFactory; //導入依賴的package包/類
private static boolean setContextAndRoot() {
	ILoggerFactory ilf = LoggerFactory.getILoggerFactory();
	if (!(ilf instanceof LoggerContext)) {
		// Not using LogBack.
		// Can't configure the logger, so just exit
		LOGGER.debug("Not using LogBack, aborting LogBack configuration");
		return false;
	}
	loggerContext = (LoggerContext) ilf;
	rootLogger = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
	if (rootLogger == null) {
		// Shouldn't be possible
		LOGGER.error("Couldn't find root logger, aborting LogBack configuration");
		return false;
	}
	return true;
}
 
開發者ID:DigitalMediaServer,項目名稱:DigitalMediaServer,代碼行數:18,代碼來源:LoggingConfig.java

示例5: setLogLevel

import org.slf4j.ILoggerFactory; //導入依賴的package包/類
/**
 * Set the log level for the requested logger name.
 *
 * @param loggerName name of the logger
 * @param logLevel the log level to set to.
 * @return the current log level of the given logger. If there is no log level configured for the given logger or
 *         if the logging implementation is not logback, {@code null} will be returned
 */
@Nullable
private String setLogLevel(String loggerName, @Nullable String logLevel) {
  ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
  if (!(loggerFactory instanceof LoggerContext)) {
    LOG.error("LoggerFactory is not a logback LoggerContext, cannot make the log level change");
    return null;
  }
  LoggerContext loggerContext = (LoggerContext) loggerFactory;

  ch.qos.logback.classic.Logger logger = loggerContext.getLogger(loggerName);
  LogEntry.Level oldLogLevel = logger.getLevel() == null ? null :
    LogEntry.Level.valueOf(logger.getLevel().toString());
  LOG.debug("Log level of {} changed from {} to {}", loggerName, oldLogLevel, logLevel);
  logger.setLevel(logLevel == null ? null : Level.toLevel(logLevel, Level.ERROR));

  return oldLogLevel == null ? null : oldLogLevel.name();
}
 
開發者ID:apache,項目名稱:twill,代碼行數:26,代碼來源:TwillContainerService.java

示例6: buildLoggerContext

import org.slf4j.ILoggerFactory; //導入依賴的package包/類
public static LoggerContext buildLoggerContext(Map<String, String> props) {
    if (loggerContext == null) {
        ILoggerFactory lcObject = LoggerFactory.getILoggerFactory();

        if (!(lcObject instanceof LoggerContext)) {
            throw new LogbackException("Expected LOGBACK binding with SLF4J, but another log system has taken the place: "
                                       + lcObject.getClass().getSimpleName());
        }

        loggerContext = (LoggerContext) lcObject;
        if (props != null) {
            for (Map.Entry<String, String> entry : props.entrySet()) {
                loggerContext.putProperty(entry.getKey(), entry.getValue());
            }
        }
    }

    return loggerContext;
}
 
開發者ID:loye168,項目名稱:tddl5,代碼行數:20,代碼來源:DynamicLogback918Logger.java

示例7: configureLogger

import org.slf4j.ILoggerFactory; //導入依賴的package包/類
private void configureLogger() {
  // Check if SLF4J is bound to logback in the current environment
  ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
  if (!(loggerFactory instanceof LoggerContext)) {
    return;
  }

  LoggerContext context = (LoggerContext) loggerFactory;
  context.reset();
  JoranConfigurator configurator = new JoranConfigurator();
  configurator.setContext(context);

  try {
    File twillLogback = new File(Constants.Files.LOGBACK_TEMPLATE);
    if (twillLogback.exists()) {
      configurator.doConfigure(twillLogback);
    }
    new ContextInitializer(context).autoConfig();
  } catch (JoranException e) {
    throw Throwables.propagate(e);
  }
  doConfigure(configurator, getLogConfig(getLoggerLevel(context.getLogger(Logger.ROOT_LOGGER_NAME))));
}
 
開發者ID:chtyim,項目名稱:incubator-twill,代碼行數:24,代碼來源:ServiceMain.java

示例8: init

import org.slf4j.ILoggerFactory; //導入依賴的package包/類
private void init() {
    BlockingQueue<ILoggingEvent> queue = new LinkedBlockingDeque<ILoggingEvent>();

    installClient(queue);

    ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
    if (!(loggerFactory instanceof LoggerContext))
        throw new IllegalStateException("This service must be run with Logback Classic");

    LoggerContext loggerContext = (LoggerContext) loggerFactory;
    ch.qos.logback.classic.Logger root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
    String appenderName = getClass().getName();
    Appender<ILoggingEvent> appender = root.getAppender(appenderName);
    if (appender != null)
        throw new IllegalStateException("Appender " + appenderName + " already configured");

    RemoteLoggerAppender remoteAppender = new RemoteLoggerAppender(queue, hostname);
    remoteAppender.setContext(loggerContext);
    remoteAppender.addFilter(MDCFilter.instance);
    remoteAppender.start();
    root.addAppender(remoteAppender);
}
 
開發者ID:mwsobol,項目名稱:SORCER,代碼行數:23,代碼來源:RemoteLoggerInstaller.java

示例9: init

import org.slf4j.ILoggerFactory; //導入依賴的package包/類
@Before
public void init() throws Exception {
       TimeZone.setDefault(TimeZone.getTimeZone("UTC"));

	request = mock(HttpServletRequest.class);
	response = mock(HttpServletResponse.class);
	registry = new EventLoggingRegistry();
	EventLogDefinition eld = new EventLogDefinition();
	eld.setRegistry(registry);
	eld.setLogName("ACCESS-LOG");
	eld.register();

       loggerFactory = mock(ILoggerFactory.class);
       oldLoggerFactory = HttpRequestLogger.setLoggerFactory(loggerFactory);
       eventLog = mock(Logger.class);
}
 
開發者ID:betfair,項目名稱:cougar,代碼行數:17,代碼來源:HttpRequestLoggerTest.java

示例10: init

import org.slf4j.ILoggerFactory; //導入依賴的package包/類
@GetMapping
public String init(Model model)
{
	ILoggerFactory iLoggerFactory = LoggerFactory.getILoggerFactory();
	if (!(iLoggerFactory instanceof LoggerContext))
	{
		throw new RuntimeException("Logger factory is not a Logback logger context");
	}
	LoggerContext loggerContext = (LoggerContext) iLoggerFactory;

	List<Logger> loggers = new ArrayList<>();
	for (ch.qos.logback.classic.Logger logger : loggerContext.getLoggerList())
	{
		if (logger.getLevel() != null || logger.iteratorForAppenders().hasNext())
		{
			loggers.add(logger);
		}
	}

	model.addAttribute("loggers", loggers);
	model.addAttribute("levels", LOG_LEVELS);
	model.addAttribute("hasWritePermission", SecurityUtils.currentUserIsSu());
	return "view-logmanager";
}
 
開發者ID:molgenis,項目名稱:molgenis,代碼行數:25,代碼來源:LogManagerController.java

示例11: resetLoggers

import org.slf4j.ILoggerFactory; //導入依賴的package包/類
@PreAuthorize("hasAnyRole('ROLE_SU')")
@PostMapping("/loggers/reset")
@ResponseStatus(HttpStatus.OK)
public void resetLoggers()
{
	ILoggerFactory iLoggerFactory = LoggerFactory.getILoggerFactory();
	if (!(iLoggerFactory instanceof LoggerContext))
	{
		throw new RuntimeException("Logger factory is not a Logback logger context");
	}
	LoggerContext loggerContext = (LoggerContext) iLoggerFactory;
	ContextInitializer ci = new ContextInitializer(loggerContext);
	URL url = ci.findURLOfDefaultConfigurationFile(true);
	loggerContext.reset();
	try
	{
		ci.configureByResource(url);
	}
	catch (JoranException e)
	{
		LOG.error("Error reloading log configuration", e);
		throw new RuntimeException(e);
	}
}
 
開發者ID:molgenis,項目名稱:molgenis,代碼行數:25,代碼來源:LogManagerController.java

示例12: initServiceLocator

import org.slf4j.ILoggerFactory; //導入依賴的package包/類
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;
}
 
開發者ID:facebook,項目名稱:buck,代碼行數:23,代碼來源:AetherUtil.java

示例13: scanContextForLoggerFactories

import org.slf4j.ILoggerFactory; //導入依賴的package包/類
private Set<Class<? extends ILoggerFactory>> scanContextForLoggerFactories() {
    final Set<Class<? extends ILoggerFactory>> loggerFactories;
    final Collection<URL> set = ClasspathHelper.forPackage(PACKAGE_TO_SCAN);
    final Reflections reflections = new Reflections(new ConfigurationBuilder().addUrls(set).setScanners(new SubTypesScanner()));

    loggerFactories = reflections.getSubTypesOf(ILoggerFactory.class);
    loggerFactories.remove(this.getClass());
    return loggerFactories;
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:10,代碼來源:CasLoggerFactory.java

示例14: getLoggerFactoryBeInstantiated

import org.slf4j.ILoggerFactory; //導入依賴的package包/類
private static ILoggerFactory getLoggerFactoryBeInstantiated(final Class<? extends ILoggerFactory> loggerFactory) {
    try {
        return loggerFactory.newInstance();
    } catch (final Exception e) {
        return null;
    }
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:8,代碼來源:CasLoggerFactory.java

示例15: CasLoggerFactory

import org.slf4j.ILoggerFactory; //導入依賴的package包/類
/**
 * Instantiates a new Cas logger factory.
 * Configures the reflection scanning engine to be prepared to scan <code>org.slf4j.impl</code>
 * in order to find other available factories.
 */
public CasLoggerFactory() {
    this.loggerMap = new ConcurrentHashMap<>();
    final Collection<URL> set = ClasspathHelper.forPackage(PACKAGE_TO_SCAN);
    final Reflections reflections = new Reflections(new ConfigurationBuilder().addUrls(set).setScanners(new SubTypesScanner()));

    final Set<Class<? extends ILoggerFactory>> subTypesOf = reflections.getSubTypesOf(ILoggerFactory.class);
    subTypesOf.remove(this.getClass());

    if (subTypesOf.size() > 1) {
        Util.report("Multiple ILoggerFactory bindings are found on the classpath:");
        for (final Class<? extends ILoggerFactory> c : subTypesOf) {
            Util.report("* " + c.getCanonicalName());
        }
    }

    if (subTypesOf.isEmpty()) {
        final RuntimeException e = new RuntimeException("No ILoggerFactory could be found on the classpath."
                + " CAS cannot determine the logging framework."
                + " Examine the project dependencies and ensure that there is one and only one logging framework available.");

        Util.report(e.getMessage(), e);
        throw e;
    }
    this.realLoggerFactoryClass = subTypesOf.iterator().next();
    Util.report("ILoggerFactory to be used for logging is: " + this.realLoggerFactoryClass.getName());
}
 
開發者ID:hsj-xiaokang,項目名稱:springboot-shiro-cas-mybatis,代碼行數:32,代碼來源:CasLoggerFactory.java


注:本文中的org.slf4j.ILoggerFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。