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


Java ContextInitializer类代码示例

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


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

示例1: init

import ch.qos.logback.classic.util.ContextInitializer; //导入依赖的package包/类
/**
 * Package access for testing purposes.
 */
void init() {
  try {
    try {
      new ContextInitializer(defaultLoggerContext).autoConfig();
    } catch (JoranException je) {
      Util.report("Failed to auto configure default logger context", je);
    }
    // logback-292
    if(!StatusUtil.contextHasStatusListener(defaultLoggerContext)) {
      StatusPrinter.printInCaseOfErrorsOrWarnings(defaultLoggerContext);
    }
    contextSelectorBinder.init(defaultLoggerContext, KEY);
    initialized = true;
  } catch (Throwable t) {
    // we should never get here
    Util.report("Failed to instantiate [" + LoggerContext.class.getName()
        + "]", t);
  }
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:23,代码来源:StaticLoggerBinder.java

示例2: init

import ch.qos.logback.classic.util.ContextInitializer; //导入依赖的package包/类
private void init() {

        String originalLogbackConfigFileValue = System.getProperty(ContextInitializer.CONFIG_FILE_PROPERTY);
        System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, findURLOfDefaultConfigurationFile());
        System.setProperty(GREENPEPPER_DEBUG_SYSPROP, Boolean.toString(GreenPepper.isDebugEnabled()));

        // Logback initialisation
        try {
            Class<?> loggerBinderClass = Class.forName(LOGGER_BINDER_CLASSNAME);
            Method getSingletonMethod = loggerBinderClass.getMethod("getSingleton");
            internalLoggerBinder = (LoggerFactoryBinder) getSingletonMethod.invoke(null);
        } catch (Exception e) {
            System.err.print("Unable to instanciate the LoggerFactoryBinder: " + e.getMessage());
            throw new IllegalStateException("Wrong configuration of greenpepper logger.", e);
        }

        if (StringUtils.isNotBlank(originalLogbackConfigFileValue)) {
            System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, originalLogbackConfigFileValue);
        } else {
            System.clearProperty(ContextInitializer.CONFIG_FILE_PROPERTY);
        }
        System.clearProperty(GREENPEPPER_DEBUG_SYSPROP);
    }
 
开发者ID:strator-dev,项目名称:greenpepper,代码行数:24,代码来源:StaticLoggerBinder.java

示例3: getLogger

import ch.qos.logback.classic.util.ContextInitializer; //导入依赖的package包/类
public static Logger getLogger(String name) {

        Logger askedLogger;
        if (!initialized) {
            synchronized (GreenPepperLogger.class) {
                String originalLogbackConfigFileValue = System.getProperty(ContextInitializer.CONFIG_FILE_PROPERTY);
                System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, "greenpepper-logback.xml");
                System.setProperty(GREENPEPPER_DEBUG_SYSPROP, Boolean.toString(GreenPepper.isDebugEnabled()));
                askedLogger = LoggerFactory.getLogger(name);
                if (StringUtils.isNotBlank(originalLogbackConfigFileValue)) {
                    System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, originalLogbackConfigFileValue);
                } else {
                    System.clearProperty(ContextInitializer.CONFIG_FILE_PROPERTY);
                }
                System.clearProperty(GREENPEPPER_DEBUG_SYSPROP);
                initialized = true;
            }
        }  else {
            askedLogger = LoggerFactory.getLogger(name);
        }
        return askedLogger;
    }
 
开发者ID:strator-dev,项目名称:greenpepper,代码行数:23,代码来源:GreenPepperLogger.java

示例4: configureLogger

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

示例5: beforeResetLogging

import ch.qos.logback.classic.util.ContextInitializer; //导入依赖的package包/类
@Before
public void beforeResetLogging() {
	LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();

	ContextInitializer ci = new ContextInitializer(loggerContext);
	URL url = ci.findURLOfDefaultConfigurationFile(true);

	try {
		JoranConfigurator configurator = new JoranConfigurator();
		configurator.setContext(loggerContext);
		loggerContext.reset();
		configurator.doConfigure(url);
	} catch (JoranException je) {
		// StatusPrinter will handle this
	}
	StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
}
 
开发者ID:aminmf,项目名称:crawljax,代码行数:18,代码来源:LogUtilTest.java

示例6: logSystemProperties

import ch.qos.logback.classic.util.ContextInitializer; //导入依赖的package包/类
/**
 * 在日志中记录一些系统信息
 */
public static void logSystemProperties(String[] args)
{
	log.info("java.version = {}; os = {}, {}, {}", System.getProperty("java.version"),
			System.getProperty("os.name"), System.getProperty("os.version"), System.getProperty("os.arch"));
	Runtime runtime = Runtime.getRuntime();
	log.info("processors = {}; jvm.heap = {}/{}M; file.encoding = {}", runtime.availableProcessors(),
			runtime.totalMemory() / 0x100000, runtime.maxMemory() / 0x100000, System.getProperty("file.encoding"));
	log.info("user.name = {}; user.dir = {}", System.getProperty("user.name"), System.getProperty("user.dir"));
	log.info("java.class.path = {}", System.getProperty("java.class.path"));
	URL url = new ContextInitializer(logCtx).findURLOfDefaultConfigurationFile(true);
	if(url == null)
		throw new Error("not found logback.xml from classpath");
	log.info("logback.path = {}", url.getPath());
	if(args != null)
	{
		for(int i = 0, n = args.length; i < n; ++i)
			log.info("arg{} = {}", i, args[i]);
	}
}
 
开发者ID:dwing4g,项目名称:jane,代码行数:23,代码来源:Log.java

示例7: 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

示例8: init

import ch.qos.logback.classic.util.ContextInitializer; //导入依赖的package包/类
/**
 * Package access for testing purposes.
 */
void init() {
	try {
		try {
			new ContextInitializer(defaultLoggerContext).autoConfig();
		} catch (JoranException je) {
			Util.report("Failed to auto configure default logger context", je);
		}
		StatusPrinter.printInCaseOfErrorsOrWarnings(defaultLoggerContext);
		contextSelectorBinder.init(defaultLoggerContext, KEY);
		initialized = true;
	} catch (Throwable t) {
		// we should never get here
		Util.report("Failed to instantiate [" + LoggerContext.class.getName() + "]", t);
	}
}
 
开发者ID:cwpenhale,项目名称:red5-mobileconsole,代码行数:19,代码来源:StaticLoggerBinder.java

示例9: 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

示例10: 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

示例11: configureByResourceUrl

import ch.qos.logback.classic.util.ContextInitializer; //导入依赖的package包/类
private void configureByResourceUrl(
		LoggingInitializationContext initializationContext,
		LoggerContext loggerContext, URL url) throws JoranException {
	if (url.toString().endsWith("xml")) {
		JoranConfigurator configurator = new SpringBootJoranConfigurator(
				initializationContext);
		configurator.setContext(loggerContext);
		configurator.doConfigure(url);
	}
	else {
		new ContextInitializer(loggerContext).configureByResource(url);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:LogbackLoggingSystem.java

示例12: locate

import ch.qos.logback.classic.util.ContextInitializer; //导入依赖的package包/类
/**
 * 自定义加载日志文件,初始化日志框架
 * @param logbackUrl	日志配置文件路径
 * @throws FileNotFoundException
 * @throws JoranException
 */
protected void locate(String logbackUrl) throws FileNotFoundException, JoranException {
	if(Strings.isBlank(logbackUrl)) return;
	logbackUrl = (logbackUrl = logbackUrl.trim()).startsWith(CLASS_PREFIX) 
			? logbackUrl : CLASS_PREFIX + logbackUrl;
	URL url = ResourceUtils.getURL(logbackUrl);
       LoggerContext loggerContext = (LoggerContext)StaticLoggerBinder.getSingleton().getLoggerFactory();
       loggerContext.reset();
       new ContextInitializer(loggerContext).configureByResource(url);
}
 
开发者ID:easycodebox,项目名称:easycode,代码行数:16,代码来源:LocateLogger.java

示例13: main

import ch.qos.logback.classic.util.ContextInitializer; //导入依赖的package包/类
static public void main(String[] args) throws Exception {
  if (args.length < 2) {
    usage("Wrong number of arguments.");
  }

  String qcfBindingName = args[0];
  String queueBindingName = args[1];
  String username = null;
  String password = null;
  if (args.length == 4) {
    username = args[2];
    password = args[3];
  }

  LoggerContext loggerContext = (LoggerContext) LoggerFactory
      .getILoggerFactory();
  new ContextInitializer(loggerContext).autoConfig();

  new JMSQueueSink(qcfBindingName, queueBindingName, username, password);

  BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
  // Loop until the word "exit" is typed
  System.out.println("Type \"exit\" to quit JMSQueueSink.");
  while (true) {
    String s = stdin.readLine();
    if (s.equalsIgnoreCase("exit")) {
      System.out.println("Exiting. Kill the application if it does not exit "
          + "due to daemon threads.");
      return;
    }
  }
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:33,代码来源:JMSQueueSink.java

示例14: main

import ch.qos.logback.classic.util.ContextInitializer; //导入依赖的package包/类
static public void main(String[] args) throws Exception {
  if (args.length < 2) {
    usage("Wrong number of arguments.");
  }

  String tcfBindingName = args[0];
  String topicBindingName = args[1];
  String username = null;
  String password = null;
  if (args.length == 4) {
    username = args[2];
    password = args[3];
  }

  LoggerContext loggerContext = (LoggerContext) LoggerFactory
      .getILoggerFactory();
  new ContextInitializer(loggerContext).autoConfig();

  new JMSTopicSink(tcfBindingName, topicBindingName, username, password);

  BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
  // Loop until the word "exit" is typed
  System.out.println("Type \"exit\" to quit JMSTopicSink.");
  while (true) {
    String s = stdin.readLine();
    if (s.equalsIgnoreCase("exit")) {
      System.out.println("Exiting. Kill the application if it does not exit "
          + "due to daemon threads.");
      return;
    }
  }
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:33,代码来源:JMSTopicSink.java

示例15: noOutputIfContextHasAStatusListener

import ch.qos.logback.classic.util.ContextInitializer; //导入依赖的package包/类
@Test
public void noOutputIfContextHasAStatusListener() {
  System.setProperty(ContextInitializer.CONFIG_FILE_PROPERTY, ClassicTestConstants.INPUT_PREFIX + "issue/logback292.xml");
  System.setProperty(ContextInitializer.STATUS_LISTENER_CLASS, NopStatusListener.class.getName());

  StaticLoggerBinderFriend.reset();
  assertEquals(0, tee.baos.size());
}
 
开发者ID:cscfa,项目名称:bartleby,代码行数:9,代码来源:InitializationOutputTest.java


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