Search in sources :

Example 1 with JoranException

use of ch.qos.logback.core.joran.spi.JoranException 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 JoranException

use of ch.qos.logback.core.joran.spi.JoranException 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 3 with JoranException

use of ch.qos.logback.core.joran.spi.JoranException 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 4 with JoranException

use of ch.qos.logback.core.joran.spi.JoranException in project chassis by Kixeye.

the class LoggingConfiguration method reloadLogging.

/**
	 * 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) {
        // Just in case, so we see a stacktrace
        ex.printStackTrace();
    }
    StatusPrinter.printInCaseOfErrorsOrWarnings(logContext);
    applicationContext.publishEvent(new LoggingReloadedApplicationEvent(this));
}
Also used : LoggingReloadedApplicationEvent(com.kixeye.chassis.support.events.LoggingReloadedApplicationEvent) ByteArrayInputStream(java.io.ByteArrayInputStream) JoranException(ch.qos.logback.core.joran.spi.JoranException) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator) LoggerContext(ch.qos.logback.classic.LoggerContext) JoranException(ch.qos.logback.core.joran.spi.JoranException)

Example 5 with JoranException

use of ch.qos.logback.core.joran.spi.JoranException in project perun by CESNET.

the class PerunLogbackConfigurator method configure.

@Override
public void configure(LoggerContext loggerContext) {
    JoranConfigurator configurator = new JoranConfigurator();
    configurator.setContext(loggerContext);
    String confDir = System.getProperty("perun.conf.custom", "/etc/perun/");
    File confFile = Paths.get(confDir, "logback.xml").toFile();
    if (confFile.exists()) {
        System.out.println("Loading logback config file " + confFile);
        try {
            // loads logback file
            configurator.doConfigure(confFile.toString());
        } catch (JoranException e) {
            e.printStackTrace();
        }
    } else {
        System.out.println("Loading logback-default.xml file from classpath");
        try (InputStream configStream = this.getClass().getResourceAsStream("/logback-default.xml")) {
            // loads logback file
            configurator.doConfigure(configStream);
            configStream.close();
        } catch (IOException | JoranException e) {
            e.printStackTrace();
            System.out.println("Falling back to logback basic configurator");
            BasicConfigurator basicConfigurator = new BasicConfigurator();
            basicConfigurator.setContext(loggerContext);
            basicConfigurator.configure(loggerContext);
        }
    }
}
Also used : BasicConfigurator(ch.qos.logback.classic.BasicConfigurator) JoranException(ch.qos.logback.core.joran.spi.JoranException) InputStream(java.io.InputStream) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator) IOException(java.io.IOException) File(java.io.File)

Aggregations

JoranException (ch.qos.logback.core.joran.spi.JoranException)14 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)11 LoggerContext (ch.qos.logback.classic.LoggerContext)8 File (java.io.File)4 InputStream (java.io.InputStream)4 URL (java.net.URL)4 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ArrayList (java.util.ArrayList)2 BasicConfigurator (ch.qos.logback.classic.BasicConfigurator)1 Logger (ch.qos.logback.classic.Logger)1 ContextInitializer (ch.qos.logback.classic.util.ContextInitializer)1 SaxEvent (ch.qos.logback.core.joran.event.SaxEvent)1 SaxEventRecorder (ch.qos.logback.core.joran.event.SaxEventRecorder)1 Status (ch.qos.logback.core.status.Status)1 StatusChecker (ch.qos.logback.core.status.StatusChecker)1 CConfiguration (co.cask.cdap.common.conf.CConfiguration)1 LogPipelineConfigurator (co.cask.cdap.logging.pipeline.LogPipelineConfigurator)1 OperationResult (com.evolveum.midpoint.schema.result.OperationResult)1 LoggingReloadedApplicationEvent (com.kixeye.chassis.support.events.LoggingReloadedApplicationEvent)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1