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