ch.qos.logback.core.util.StatusPrinter Java Examples

The following examples show how to use ch.qos.logback.core.util.StatusPrinter. 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: ITestApplication.java    From camel-spring-boot with Apache License 2.0 7 votes vote down vote up
private static void overrideLoggingConfig() {

        URL logbackFile = ITestApplication.class.getResource("/spring-logback.xml");
        if (logbackFile != null) {

            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(logbackFile);
            } catch (JoranException je) {
                // StatusPrinter will handle this
            }
            StatusPrinter.printInCaseOfErrorsOrWarnings(context);
        }

    }
 
Example #2
Source File: Generator.java    From gd-generator with MIT License 6 votes vote down vote up
public static void load() throws JoranException {
    final String s = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
            "<configuration debug=\"true\">\n" +
            "\t<appender name=\"STDOUT\" class=\"ch.qos.logback.core.ConsoleAppender\">\n" +
            "\t\t<encoder>\n" +
            "\t\t\t<charset>UTF-8</charset>\n" +
            "\t\t\t<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} - %msg%n</pattern>\n" +
            "\t\t</encoder>\n" +
            "\t</appender>\n" +
            "\t<root level=\"INFO\">\n" +
            "\t\t<appender-ref ref=\"STDOUT\"/>\n" +
            "\t</root>\n" +
            "</configuration>";
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(new ByteArrayInputStream(s.getBytes(Charset.forName("UTF-8"))));
    StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}
 
Example #3
Source File: Global.java    From NationStatesPlusPlus with MIT License 6 votes vote down vote up
private static void setupLogback() {
	LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
	Logger.info("Setting up Logback");
	Logger.info("Application running from: {}", Start.getApplicationDirectory().getAbsolutePath());
	System.setProperty("application.home", Start.getApplicationDirectory().getAbsolutePath());
	File xmlConfig = new File(new File(Start.getApplicationDirectory(), "conf"), "application-logger.xml");
	if (xmlConfig.exists()) {
		try {
			JoranConfigurator configurator = new JoranConfigurator();
			configurator.setContext(context);
			context.reset();
			configurator.doConfigure(xmlConfig);
		} catch (JoranException je) {
			// StatusPrinter will handle this
		}
	}
	//System.setOut(new PrintStream(new LoggerOutputStream(Level.INFO, Logger.underlying()), true));
	System.setErr(new PrintStream(new LoggerOutputStream(Level.OFF, Logger.underlying()), true));
	Logger.info("Logback Setup");
	StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
 
Example #4
Source File: App.java    From PeerWasp with MIT License 6 votes vote down vote up
/**
 * Initializes the logging framework.
 * The automatic configuration is reset and the logger is configured dynamically:
 * - The log folder is set
 * - The log configuration is loaded (not from resources, but from the working directory).
 *
 * This allows switching the folder and the configuration during development and at deployment.
 */
private void initializeLogging() {
	LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
	try {
		JoranConfigurator jc = new JoranConfigurator();
		jc.setContext(context);
		// override default configuration
		context.reset();
		// inject the location of the appdata log folder as "LOG_FOLDER"
		// property of the LoggerContext
		context.putProperty("LOG_FOLDER", AppData.getLogFolder().toString());
		jc.doConfigure(LOG_CONFIGURATION);
	} catch (JoranException je) {
		// status printer will handle printing of error
	}
	StatusPrinter.printInCaseOfErrorsOrWarnings(context);
	logger.debug("Initialized logging (LOG_FOLDER={})", context.getProperty("LOG_FOLDER"));
}
 
Example #5
Source File: LoggingConfiguration.java    From chassis with Apache License 2.0 6 votes vote down vote up
/**
 * Reloads logging.
 * 
 * @param logbackConfig XML containing the logback configuration
 */
public void reloadLogging(String logbackConfig) {
	LoggerContext logContext = (LoggerContext) LoggerFactory.getILoggerFactory();
	
	try {
		JoranConfigurator configurator = new JoranConfigurator();
		configurator.setContext(logContext);
		logContext.reset();
		configurator.doConfigure(new ByteArrayInputStream(logbackConfig.getBytes(Charsets.UTF_8)));
	} catch (JoranException je) {
		// StatusPrinter will handle this
	} catch (Exception ex) {
		ex.printStackTrace(); // Just in case, so we see a stacktrace
	}
	
	StatusPrinter.printInCaseOfErrorsOrWarnings(logContext);
	
	applicationContext.publishEvent(new LoggingReloadedApplicationEvent(this));
}
 
Example #6
Source File: LoggingUtilities.java    From waltz with Apache License 2.0 6 votes vote down vote up
/**
 * Initialises logging for Waltz.  This will attempt to locate a
 * file called <code>waltz-logback.xml</code> from either:
 * <ul>
 *     <li>
 *         root of classpath
 *     </li>
 *     <li>
 *         directory: <code>${user.home}/.waltz</code>
 *     </li>
 * </ul>
 *
 * Note: this file is allowed to use System.out to communicate
 * failures to the operator.
 */
public static void configureLogging() {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    try {
        JoranConfigurator configurator = new JoranConfigurator();
        context.reset();
        configurator.setContext(context);
        System.out.println("Attempting to load logback configuration file: " + LOG_CONFIG_FILE_NAME
                            + " from classpath or " + System.getProperty("user.home") + "/.waltz/");

        Resource logbackConfigFile = IOUtilities.getFileResource(LOG_CONFIG_FILE_NAME);

        if (logbackConfigFile.exists()) {
            System.out.println("Found logback configuration file: " + logbackConfigFile);
            try (InputStream configInputStream = logbackConfigFile.getInputStream()) {
                configurator.doConfigure(configInputStream);
            }
        } else {
            System.out.println("Logback configuration file not found..");
        }
    } catch (IOException | JoranException e) {
        // StatusPrinter will handle this
    }
    StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
 
Example #7
Source File: Application.java    From acme_client with MIT License 6 votes vote down vote up
private static void configureLogger(String logDir, String logLevel, String logbackConf) {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    try {
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(context);
        context.reset();
        if (!logDir.endsWith(File.separator))
            logDir+= File.separator;
        context.putProperty("LOG_DIR", logDir);
        context.putProperty("LOG_LEVEL", logLevel);

        InputStream is = classloader.getResourceAsStream(logbackConf);
        configurator.doConfigure(is);
    } catch (JoranException je) {
        LOG.warn("Cannot configure logger. Continue to execute the command.", je);
    }
    StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
 
Example #8
Source File: KonkerStaticLoggerBinder.java    From konker-platform with Apache License 2.0 6 votes vote down vote up
void init() {
    try {
        try {
            (new KonkerContextInitializer(this.defaultLoggerContext)).autoConfig();
        } catch (JoranException var2) {
            Util.report("Failed to auto configure default logger context", var2);
        }

        if(!StatusUtil.contextHasStatusListener(this.defaultLoggerContext)) {
            StatusPrinter.printInCaseOfErrorsOrWarnings(this.defaultLoggerContext);
        }

        this.contextSelectorBinder.init(this.defaultLoggerContext, KEY);
        this.initialized = true;
    } catch (Throwable var3) {
        Util.report("Failed to instantiate [" + LoggerContext.class.getName() + ']', var3);
    }

}
 
Example #9
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 #10
Source File: LogUtils.java    From litchi with Apache License 2.0 6 votes vote down vote up
public static void loadFileConfig(String configFilePath) throws IOException, JoranException {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    File externalConfigFile = new File(configFilePath);

    if (!externalConfigFile.isFile()) {
        throw new IOException("logback config file not exists. configFilePath = " + configFilePath);
    }

    if (!externalConfigFile.canRead()) {
        throw new IOException("logback config file cannot be read. configFilePath = " + configFilePath);
    }

    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(configFilePath);
    StatusPrinter.printInCaseOfErrorsOrWarnings(lc);

}
 
Example #11
Source File: InitLogBack.java    From es_data_export with Apache License 2.0 6 votes vote down vote up
public static void init() throws Exception{
		//String configFilepathName = FilePathHelper.getFilePathWithJar("logback.xml");
       File file = new File(Constant.LOGBACK_CONFIG_NAME);
       if(!file.exists()){
       	throw new NullPointerException("logback.xml为空");
       }
       LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
       //注意包不要引错
       JoranConfigurator joranConfigurator = new JoranConfigurator();
       joranConfigurator.setContext(loggerContext);
       loggerContext.reset();
       try {
           joranConfigurator.doConfigure(file);
       } catch (Exception e) {
       	throw e;
       }
       StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
}
 
Example #12
Source File: LogbackPlugin.java    From dapeng-soa with Apache License 2.0 6 votes vote down vote up
@Override
public void start() {
    LOGGER.warn("Plugin::" + getClass().getSimpleName() + "::start");

    try (InputStream logbackCnfgStream = new BufferedInputStream(DapengContainer.loadInputStreamInClassLoader("logback.xml"))) {
        LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(lc);
        lc.reset();
        configurator.doConfigure(logbackCnfgStream);

        StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
    } catch (Exception e) {
        LOGGER.error("LogbackContainer failed, ignoring ..." + e.getMessage(), e);
        // throw new RuntimeException(e);
    }
}
 
Example #13
Source File: ConsoleLogApplicationTests.java    From spring-cloud-formula with Apache License 2.0 6 votes vote down vote up
@Test
public void contextLoads() {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    String val = context.getProperty(SpacedLogbackSystem.KEY_ENABLED);
    Assert.assertEquals("true", val);
    Logger logger = context.getLogger("com.baidu");
    Assert.assertEquals(Level.DEBUG, logger.getLevel());
    logger = context.getLogger("com.baidu.ebiz");
    Assert.assertEquals(Level.WARN, logger.getLevel());

    logger = context.getLogger("ROOT");
    List<Appender<ILoggingEvent>> list = StreamSupport.stream(
            Spliterators.spliteratorUnknownSize(
                    logger.iteratorForAppenders(), Spliterator.ORDERED), false)
            .collect(Collectors.toList());

    Assert.assertThat(list.size(), Matchers.greaterThan(1));

    LoggerFactory.getLogger("com.baidu").info("info for root");
    StatusPrinter.print(context);
}
 
Example #14
Source File: LogbackTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws JoranException {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(new File("src/test/resources/logback-example.xml"));
    StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}
 
Example #15
Source File: LogModule.java    From guacamole-client with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {

    // Only load logback configuration if GUACAMOLE_HOME exists
    File guacamoleHome = environment.getGuacamoleHome();
    if (!guacamoleHome.isDirectory())
        return;

    // Check for custom logback.xml
    File logbackConfiguration = new File(guacamoleHome, "logback.xml");
    if (!logbackConfiguration.exists())
        return;

    logger.info("Loading logback configuration from \"{}\".", logbackConfiguration);

    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.reset();

    try {

        // Initialize logback
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(context);
        configurator.doConfigure(logbackConfiguration);

        // Dump any errors that occur during logback init
        StatusPrinter.printInCaseOfErrorsOrWarnings(context);

    }
    catch (JoranException e) {
        logger.error("Initialization of logback failed: {}", e.getMessage());
        logger.debug("Unable to load logback configuration..", e);
    }

}
 
Example #16
Source File: WarServerInitializer.java    From BIMserver with GNU Affero General Public License v3.0 5 votes vote down vote up
private void setupLogging(Path homeDir) {
	LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
	try {
		JoranConfigurator configurator = new JoranConfigurator();
		configurator.setContext(context);
		context.reset();
		configurator.doConfigure(homeDir.resolve("logback.xml").toFile());
	} catch (JoranException je) {
		// StatusPrinter will handle this
	}
	StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
 
Example #17
Source File: RedisAppenderTest.java    From logback-redis-appender with Apache License 2.0 5 votes vote down vote up
protected void configLogger(String loggerxml) {
	LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();

	try {
		JoranConfigurator configurator = new JoranConfigurator();
		configurator.setContext(context);
		context.reset();
		configurator.doConfigure(this.getClass().getResourceAsStream(loggerxml));
	} catch (JoranException je) {
		// StatusPrinter will handle this
	}
	StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
 
Example #18
Source File: LogConfigurator.java    From gocd with Apache License 2.0 5 votes vote down vote up
protected void configureWith(URL resource) {
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext((LoggerContext) loggerFactory);
    ((LoggerContext) loggerFactory).reset();

    // the statusManager keeps a copy of all logback status messages even after reset, so we clear that
    ((LoggerContext) loggerFactory).getStatusManager().clear();
    try {
        configurator.doConfigure(resource);
    } catch (JoranException ignore) {
    }
    StatusPrinter.printInCaseOfErrorsOrWarnings((Context) loggerFactory);
}
 
Example #19
Source File: LoggingConfigurator.java    From logging-java with Apache License 2.0 5 votes vote down vote up
/**
 * Configure logging using a logback configuration file.
 *
 * @param file         A logback configuration file.
 * @param defaultIdent Fallback logging identity, used if not specified in config file.
 */
public static void configure(final File file, final String defaultIdent) {
  final Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);

  // Setup context
  final LoggerContext context = rootLogger.getLoggerContext();
  context.reset();

  // Log uncaught exceptions
  UncaughtExceptionLogger.setDefaultUncaughtExceptionHandler();

  // Load logging configuration from file
  try {
    final JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(context);
    configurator.doConfigure(file);
  } catch (JoranException je) {
    // StatusPrinter will handle this
  }

  context.putProperty("pid", getMyPid());
  final String hostname = getSpotifyHostname();
  if (hostname != null) {
    context.putProperty("hostname", hostname);
  }

  final String ident = context.getProperty("ident");
  if (ident == null) {
    context.putProperty("ident", defaultIdent);
  }

  StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
 
Example #20
Source File: BookstoreLogger.java    From spring-data-rest-acl with Apache License 2.0 5 votes vote down vote up
private void init() {
	JoranConfigurator configurator = new JoranConfigurator();
	LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
       configurator.setContext(loggerContext);
       loggerContext.reset();
       try {
		configurator.doConfigure(logbackconfig);
	} catch (JoranException e) {
		// StatusPrinter will handle this
	}
       StatusPrinter.printInCaseOfErrorsOrWarnings(loggerContext);
       
       logger.info("Test Log");		
       logger.error("error msg");
}
 
Example #21
Source File: LogbackTest.java    From DDMQ with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws JoranException {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(new File("src/test/resources/logback-example.xml"));
    StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}
 
Example #22
Source File: LogbackTest.java    From rocketmq-4.3.0 with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws JoranException {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(new File("src/test/resources/logback-example.xml"));
    StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}
 
Example #23
Source File: LogbackTest.java    From rocketmq-read with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws JoranException {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(new File("src/test/resources/logback-example.xml"));
    StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}
 
Example #24
Source File: LogbackTest.java    From rocketmq with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws JoranException {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(new File("src/test/resources/logback-example.xml"));
    StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}
 
Example #25
Source File: LogModule.java    From guacamole-client with Apache License 2.0 5 votes vote down vote up
@Override
protected void configure() {

    // Only load logback configuration if GUACAMOLE_HOME exists
    File guacamoleHome = environment.getGuacamoleHome();
    if (!guacamoleHome.isDirectory())
        return;

    // Check for custom logback.xml
    File logbackConfiguration = new File(guacamoleHome, "logback.xml");
    if (!logbackConfiguration.exists())
        return;

    logger.info("Loading logback configuration from \"{}\".", logbackConfiguration);

    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    context.reset();

    try {

        // Initialize logback
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(context);
        configurator.doConfigure(logbackConfiguration);

        // Dump any errors that occur during logback init
        StatusPrinter.printInCaseOfErrorsOrWarnings(context);

    }
    catch (JoranException e) {
        logger.error("Initialization of logback failed: {}", e.getMessage());
        logger.debug("Unable to load logback configuration..", e);
    }

}
 
Example #26
Source File: LoggingBootstrap.java    From hivemq-community-edition with Apache License 2.0 5 votes vote down vote up
/**
 * Overrides the standard Logging configuration delivered with HiveMQ with
 * a logback.xml from the config folder.
 *
 * @return If the default configuration was overridden
 */
private static boolean overrideLogbackXml(final @NotNull File configFolder) {
    final File file = new File(configFolder, "logback.xml");
    if (file.canRead()) {
        log.info("Log Configuration was overridden by {}", file.getAbsolutePath());
        final LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
        try {
            context.reset();

            final JoranConfigurator configurator = new JoranConfigurator();
            configurator.setContext(context);
            configurator.doConfigure(file);

            context.getLogger(Logger.ROOT_LOGGER_NAME).addAppender(listAppender);
            return true;
        } catch (final JoranException je) {
            // StatusPrinter will handle this
        } catch (final Exception ex) {
            // Just in case, so we see a stacktrace if the logger could not be initialized
            ex.printStackTrace();
        } finally {
            StatusPrinter.printInCaseOfErrorsOrWarnings(context);
        }
        // Print internal status data in case of warnings or errors.
        return false;
    } else {
        log.warn(
                "The logging configuration file {} does not exist. Using HiveMQ default logging configuration.",
                file.getAbsolutePath());
        return false;
    }
}
 
Example #27
Source File: TplCLI.java    From LibScout with Apache License 2.0 5 votes vote down vote up
private static void initLogging() {
	LoggerContext context = (LoggerContext) org.slf4j.LoggerFactory.getILoggerFactory();
	    
	try {
		JoranConfigurator configurator = new JoranConfigurator();
	    configurator.setContext(context);
	    context.reset();  // clear any previous configuration 
	    configurator.doConfigure(LibScoutConfig.log4jConfigFileName);
	    
    	ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
    	switch (LibScoutConfig.logType) {
			case CONSOLE:
				rootLogger.detachAppender("FILE");
				break;
			case FILE:
				rootLogger.detachAppender("CONSOLE");
				break;
			case NONE:
				rootLogger.detachAndStopAllAppenders();
				break;
    	}
	} catch (JoranException je) {
		// StatusPrinter will handle this
	}
	
	StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
 
Example #28
Source File: LogbackTest.java    From rocketmq-all-4.1.0-incubating with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws JoranException {
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(new File("src/test/resources/logback-example.xml"));
    StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}
 
Example #29
Source File: LogbackConfigurer.java    From icure-backend with GNU General Public License v2.0 5 votes vote down vote up
public static void initLogging(URL configUrl) {
	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(configUrl);
	} catch (JoranException je) {
		// StatusPrinter will handle this
	}
	StatusPrinter.printIfErrorsOccured(context);
}
 
Example #30
Source File: SylphMaster.java    From sylph with Apache License 2.0 5 votes vote down vote up
/**
 * 加载外部的logback配置文件
 */
private static void loadConfig(String logbackXml)
        throws JoranException
{
    LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(lc);
    lc.reset();
    configurator.doConfigure(logbackXml);
    StatusPrinter.printInCaseOfErrorsOrWarnings(lc);
}