Search in sources :

Example 1 with ContextInitializer

use of ch.qos.logback.classic.util.ContextInitializer in project weave by continuuity.

the class ServiceMain method configureLogger.

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 weaveLogback = new File(Constants.Files.LOGBACK_TEMPLATE);
        if (weaveLogback.exists()) {
            configurator.doConfigure(weaveLogback);
        }
        new ContextInitializer(context).autoConfig();
    } catch (JoranException e) {
        throw Throwables.propagate(e);
    }
    doConfigure(configurator, getLogConfig(getLoggerLevel(context.getLogger(Logger.ROOT_LOGGER_NAME))));
}
Also used : ContextInitializer(ch.qos.logback.classic.util.ContextInitializer) ILoggerFactory(org.slf4j.ILoggerFactory) JoranException(ch.qos.logback.core.joran.spi.JoranException) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator) LoggerContext(ch.qos.logback.classic.LoggerContext) File(java.io.File)

Example 2 with ContextInitializer

use of ch.qos.logback.classic.util.ContextInitializer in project spring-boot by spring-projects.

the class LogbackLoggingSystem method configureByResourceUrl.

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);
    }
}
Also used : ContextInitializer(ch.qos.logback.classic.util.ContextInitializer) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator)

Aggregations

JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)2 ContextInitializer (ch.qos.logback.classic.util.ContextInitializer)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 JoranException (ch.qos.logback.core.joran.spi.JoranException)1 File (java.io.File)1 ILoggerFactory (org.slf4j.ILoggerFactory)1