当前位置: 首页>>代码示例>>Java>>正文


Java ContextInitializer.configureByResource方法代码示例

本文整理汇总了Java中ch.qos.logback.classic.util.ContextInitializer.configureByResource方法的典型用法代码示例。如果您正苦于以下问题:Java ContextInitializer.configureByResource方法的具体用法?Java ContextInitializer.configureByResource怎么用?Java ContextInitializer.configureByResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ch.qos.logback.classic.util.ContextInitializer的用法示例。


在下文中一共展示了ContextInitializer.configureByResource方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: resetLoggers

import ch.qos.logback.classic.util.ContextInitializer; //导入方法依赖的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

示例2: adjustDetailedTracing

import ch.qos.logback.classic.util.ContextInitializer; //导入方法依赖的package包/类
public static void adjustDetailedTracing(SystemProperties config, long blockNum) {
    // here we can turn on the detail tracing in the middle of the chain
    if (blockNum >= config.traceStartBlock() && config.traceStartBlock() != -1) {
        final URL configFile = ClassLoader.getSystemResource("logback-detailed.xml");
        final LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
        final ContextInitializer ci = new ContextInitializer(loggerContext);

        loggerContext.reset();
        try {
            ci.configureByResource(configFile);
        } catch (Exception e) {
            System.out.println("Error applying new config " + e.getMessage());
        }
    }
}
 
开发者ID:talentchain,项目名称:talchain,代码行数:16,代码来源:AdvancedDeviceUtils.java

示例3: configureLogger

import ch.qos.logback.classic.util.ContextInitializer; //导入方法依赖的package包/类
private void configureLogger() throws MalformedURLException, JoranException {
  // Check if SLF4J is bound to logback in the current environment
  ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
  if (!(loggerFactory instanceof LoggerContext)) {
    return;
  }

  LoggerContext context = (LoggerContext) loggerFactory;

  ContextInitializer contextInitializer = new ContextInitializer(context);
  URL url = contextInitializer.findURLOfDefaultConfigurationFile(false);
  if (url == null) {
    // The logger context was not initialized using configuration file, initialize it with the logback template.
    File twillLogback = new File(Constants.Files.RUNTIME_CONFIG_JAR, Constants.Files.LOGBACK_TEMPLATE);
    if (twillLogback.exists()) {
      contextInitializer.configureByResource(twillLogback.toURI().toURL());
    }
  }

  // Attach the KafkaAppender to the root logger
  KafkaAppender kafkaAppender = new KafkaAppender();
  kafkaAppender.setName("KAFKA");
  kafkaAppender.setTopic(Constants.LOG_TOPIC);
  kafkaAppender.setHostname(getHostname());
  // The Kafka ZK Connection shouldn't be null as this method only get called if log collection is enabled
  kafkaAppender.setZookeeper(getTwillRuntimeSpecification().getKafkaZKConnect());
  String runnableName = getRunnableName();
  if (runnableName != null) {
    kafkaAppender.setRunnableName(runnableName);
  }

  kafkaAppender.setContext(context);
  kafkaAppender.start();

  context.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME).addAppender(kafkaAppender);
}
 
开发者ID:apache,项目名称:twill,代码行数:37,代码来源:ServiceMain.java

示例4: configureLogback

import ch.qos.logback.classic.util.ContextInitializer; //导入方法依赖的package包/类
public static void configureLogback(Object rawContext) {
    if (rawContext instanceof LoggerContext) {
        LoggerContext context = (LoggerContext)rawContext;
        ContextInitializer initializer = new ContextInitializer(context);
        if (initializer.findURLOfDefaultConfigurationFile(false) == null) {
            context.reset();
            URL defaultConfig = context.getClass().getClassLoader().getResource("logback-default.xml");
            try {
                initializer.configureByResource(defaultConfig);
            } catch (JoranException e) {
                throw new RuntimeException("Failed to load default logging configuration", e);
            }
        }
    }
}
 
开发者ID:projectodd,项目名称:wunderboss,代码行数:16,代码来源:LogbackUtil.java


注:本文中的ch.qos.logback.classic.util.ContextInitializer.configureByResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。