Java Code Examples for ch.qos.logback.core.joran.spi.JoranException#printStackTrace()

The following examples show how to use ch.qos.logback.core.joran.spi.JoranException#printStackTrace() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractSmartClient.java    From SmartIM with Apache License 2.0 6 votes vote down vote up
@Override
public void setWorkDir(File path) {
    if (path == null) {
        throw new IllegalArgumentException("Work directory is null");
    }
    if (!path.exists()) {
        path.mkdirs();
    }
    this.workDir = path;
    System.setProperty("log.home", path.getAbsolutePath());
    ILoggerFactory fac = LoggerFactory.getILoggerFactory();
    if (fac != null && fac instanceof LoggerContext) {
        LoggerContext lc = (LoggerContext) fac;
        lc.getStatusManager().clear();
        lc.reset();
        lc.putProperty("log.home", path.getAbsolutePath());
        ContextInitializer ci = new ContextInitializer(lc);
        try {
            ci.autoConfig();
        } catch (JoranException e) {
            e.printStackTrace();
        }
    }
}
 
Example 2
Source File: LogbackConfiguration.java    From rdf4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void load() throws IOException {
	try {
		if (System.getProperty(LOGGING_DIR_PROPERTY) == null) {
			System.setProperty(LOGGING_DIR_PROPERTY, getLoggingDir().getAbsolutePath());
		}
	} catch (SecurityException e) {
		System.out.println("Not allowed to read or write system property '" + LOGGING_DIR_PROPERTY + "'");
	}

	LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
	try {
		configurator = new LogConfigurator();
		configurator.setContext(lc);
		lc.reset();
		configurator.doConfigure(configFile);
	} catch (JoranException je) {
		System.out.println("Logback configuration error");
		je.printStackTrace();
		StatusPrinter.print(lc);
	}
}
 
Example 3
Source File: MyLoggerListenerTest.java    From ns4_frame with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) 
	{
		URL url = Thread.currentThread().getContextClassLoader().getResource("joran_test.xml");
		
		//加载配置文件 然后获取logger 打印日志
		LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

		try {
			JoranConfigurator configurator = new JoranConfigurator();
			configurator.setContext(context);
			// Call context.reset() to clear any previous configuration, e.g. default 
			// configuration. For multi-step configuration, omit calling context.reset().
			context.reset(); 
			configurator.doConfigure(url.getPath());
			
//			logger.info("哈哈哈哈");
			
		} catch (JoranException je) {
			// StatusPrinter will handle this
			je.printStackTrace();
			return;
		}
		
		logger.info("哈哈哈哈哈哈||{}",1111);
		
		
	}
 
Example 4
Source File: TestThreadLogger.java    From ns4_frame with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws InterruptedException 
{
	URL url = Thread.currentThread().getContextClassLoader().getResource("logback_thread.xml");
	
	//加载配置文件 然后获取logger 打印日志
	LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

	try {
		JoranConfigurator configurator = new JoranConfigurator();
		configurator.setContext(context);
		// Call context.reset() to clear any previous configuration, e.g. default 
		// configuration. For multi-step configuration, omit calling context.reset().
		context.reset(); 
		configurator.doConfigure(url.getPath());
	} catch (JoranException je) {
		// StatusPrinter will handle this
		je.printStackTrace();
		return;
	}
	
	
	//文件名
	TestThreadLogger testThreadLogger =  new TestThreadLogger();
	testThreadLogger.start();
	
	
	TestThreadLogger testThreadLogger1 =  new TestThreadLogger();
	testThreadLogger1.start();
	
	
	TestThreadLogger testThreadLogger2 =  new TestThreadLogger();
	testThreadLogger2.start();
	
	testThreadLogger.join();
	testThreadLogger1.join();
	testThreadLogger2.join();
	
}
 
Example 5
Source File: TestConfig.java    From iot-mqtt with Apache License 2.0 5 votes vote down vote up
public TestConfig(String configPath) {
	super(configPath);
       LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
       JoranConfigurator configurator = new JoranConfigurator();
       configurator.setContext(lc);
       lc.reset();
       try {
		configurator.doConfigure(getLogBackXmlPath());
	} catch (JoranException e) {
		e.printStackTrace();
	}
}
 
Example 6
Source File: LoggerFactory.java    From TarsJava with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static int resetLogBack() {
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(logContext);
    logContext.reset();
    try {
        configurator.doConfigure("logback.xml");
        return 0;
    } catch (JoranException e) {
        e.printStackTrace();
        return -1;
    }
}