本文整理汇总了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);
}
}
示例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());
}
}
}
示例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);
}
示例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);
}
}
}
}