Search in sources :

Example 1 with JoranConfigurator

use of ch.qos.logback.classic.joran.JoranConfigurator 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 JoranConfigurator

use of ch.qos.logback.classic.joran.JoranConfigurator in project sonarqube by SonarSource.

the class LogbackHelper method resetFromXml.

/**
   * Generally used to reset logback in logging tests
   */
public void resetFromXml(String xmlResourcePath) throws JoranException {
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(context);
    context.reset();
    configurator.doConfigure(LogbackHelper.class.getResource(xmlResourcePath));
}
Also used : JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator) LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 3 with JoranConfigurator

use of ch.qos.logback.classic.joran.JoranConfigurator in project ninja by ninjaframework.

the class LogbackConfigurator method initConfiguration.

public static void initConfiguration(NinjaProperties ninjaProperties) {
    // If that is the case we do nothing and leave everything to LogBack
    if (System.getProperty(LOGBACK_CONFIGURATION_FILE_PROPERTY) != null) {
        return;
    }
    // If not we check if we got a logback configurationFile declared
    // in our application.conf and load it...
    String logbackConfigurationFile = ninjaProperties.get(LOGBACK_CONFIGURATION_FILE_PROPERTY);
    if (logbackConfigurationFile == null) {
        return;
    }
    URL logbackConfigurationFileAsURL = getUrlForStringFromClasspathAsFileOrUrl(logbackConfigurationFile);
    if (logbackConfigurationFileAsURL == null) {
        logger.error("Cannot configure logger from {} provided in application.conf", logbackConfigurationFile);
        return;
    }
    // At that point we got a valid Url for configuring Logback. Let's do it :)
    // assume SLF4J is bound to logback in the current environment
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    try {
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(context);
        context.reset();
        configurator.doConfigure(logbackConfigurationFileAsURL);
    } catch (JoranException je) {
    // StatusPrinter will handle this
    }
    logger.info("Successfully configured application logging from: {}", logbackConfigurationFileAsURL);
    StatusPrinter.printInCaseOfErrorsOrWarnings(context);
}
Also used : JoranException(ch.qos.logback.core.joran.spi.JoranException) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator) LoggerContext(ch.qos.logback.classic.LoggerContext) URL(java.net.URL)

Example 4 with JoranConfigurator

use of ch.qos.logback.classic.joran.JoranConfigurator in project stash-codesearch-plugin by palantir.

the class PluginLoggerFactory method init.

private void init() {
    // Assumes LSF4J is bound to logback
    context = (LoggerContext) LoggerFactory.getILoggerFactory();
    // store the home dir to use for relative paths
    context.putProperty("stash.home", homeDir);
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(context);
    InputStream is;
    is = this.getClass().getClassLoader().getResourceAsStream("logback-test.xml");
    if (is != null) {
        stashRootLogger.info("Using logback-test.xml for logger settings");
    } else {
        stashRootLogger.info("Using logback.xml for logger settings");
        is = this.getClass().getClassLoader().getResourceAsStream("logback.xml");
    }
    try {
        configurator.doConfigure(is);
    } catch (JoranException e) {
        System.err.println("Error configuring logging framework" + e);
    }
    stashRootLogger.info("Logger using stash.home of " + homeDir);
}
Also used : JoranException(ch.qos.logback.core.joran.spi.JoranException) InputStream(java.io.InputStream) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator)

Example 5 with JoranConfigurator

use of ch.qos.logback.classic.joran.JoranConfigurator 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)24 LoggerContext (ch.qos.logback.classic.LoggerContext)15 JoranException (ch.qos.logback.core.joran.spi.JoranException)12 File (java.io.File)7 Test (org.junit.Test)6 InputStream (java.io.InputStream)4 Logger (org.slf4j.Logger)4 AppenderContext (co.cask.cdap.api.logging.AppenderContext)3 NoOpMetricsCollectionService (co.cask.cdap.common.metrics.NoOpMetricsCollectionService)3 DatasetFramework (co.cask.cdap.data2.dataset2.DatasetFramework)3 LocalAppenderContext (co.cask.cdap.logging.framework.LocalAppenderContext)3 StringReader (java.io.StringReader)3 URL (java.net.URL)3 InputSource (org.xml.sax.InputSource)3 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)2 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)2 ContextInitializer (ch.qos.logback.classic.util.ContextInitializer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 StringWriter (java.io.StringWriter)2 Transformer (javax.xml.transform.Transformer)2