Search in sources :

Example 16 with JoranException

use of ch.qos.logback.core.joran.spi.JoranException in project GeoGig by boundlessgeo.

the class Logging method tryConfigureLogging.

static void tryConfigureLogging(Platform platform) {
    // instantiate and call ResolveGeogigDir directly to avoid calling getGeogig() and hence get
    // some logging events before having configured logging
    final Optional<URL> geogigDirUrl = new ResolveGeogigDir(platform).call();
    if (!geogigDirUrl.isPresent() || !"file".equalsIgnoreCase(geogigDirUrl.get().getProtocol())) {
        // redirect java.util.logging to SLF4J anyways
        SLF4JBridgeHandler.removeHandlersForRootLogger();
        SLF4JBridgeHandler.install();
        return;
    }
    final File geogigDir;
    try {
        geogigDir = new File(geogigDirUrl.get().toURI());
    } catch (URISyntaxException e) {
        throw Throwables.propagate(e);
    }
    if (geogigDir.equals(geogigDirLoggingConfiguration)) {
        return;
    }
    if (!geogigDir.exists() || !geogigDir.isDirectory()) {
        return;
    }
    final URL loggingFile = getOrCreateLoggingConfigFile(geogigDir);
    if (loggingFile == null) {
        return;
    }
    try {
        LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
        loggerContext.reset();
        /*
             * Set the geogigdir variable for the config file can resolve the default location
             * ${geogigdir}/log/geogig.log
             */
        loggerContext.putProperty("geogigdir", geogigDir.getAbsolutePath());
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(loggerContext);
        configurator.doConfigure(loggingFile);
        // redirect java.util.logging to SLF4J
        SLF4JBridgeHandler.removeHandlersForRootLogger();
        SLF4JBridgeHandler.install();
        geogigDirLoggingConfiguration = geogigDir;
    } catch (JoranException e) {
        LOGGER.error("Error configuring logging from file {}. '{}'", loggingFile, e.getMessage(), e);
    }
}
Also used : JoranException(ch.qos.logback.core.joran.spi.JoranException) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator) URISyntaxException(java.net.URISyntaxException) ResolveGeogigDir(org.locationtech.geogig.api.plumbing.ResolveGeogigDir) File(java.io.File) LoggerContext(ch.qos.logback.classic.LoggerContext) URL(java.net.URL)

Example 17 with JoranException

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

the class LogConfigurator method configureWith.

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);
}
Also used : JoranException(ch.qos.logback.core.joran.spi.JoranException) JoranConfigurator(ch.qos.logback.classic.joran.JoranConfigurator) LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 18 with JoranException

use of ch.qos.logback.core.joran.spi.JoranException in project sulky by huxi.

the class LoggingTestBase method resetLogging.

@SuppressWarnings({ "PMD.AvoidPrintStackTrace" })
public static void resetLogging(boolean verbose) {
    if (verbose) {
        System.out.println("### Resetting logging configuration.");
    }
    ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
    if (loggerFactory instanceof LoggerContext) {
        LoggerContext loggerContext = (LoggerContext) loggerFactory;
        // reset previous configuration initially loaded from logback.xml
        if (verbose) {
            System.out.println("\nAbout to reset logging system.");
        }
        loggerContext.reset();
        JoranConfigurator configurator = new JoranConfigurator();
        configurator.setContext(loggerContext);
        URL configUrl;
        configUrl = LoggingTestBase.class.getResource("/logback-test.xml");
        if (configUrl == null) {
            configUrl = LoggingTestBase.class.getResource("/logback.xml");
        }
        try {
            configurator.doConfigure(configUrl);
            if (verbose) {
                System.out.println("\nPrinting status of logging system:");
                StatusPrinter.print(loggerContext);
            }
        } catch (JoranException ex) {
            System.err.println("!!! Error configuring logging framework with '" + configUrl + "'!");
            // this is not a bug! - Avoid Print Stack Trace : Avoid printStackTrace(); use a logger call instead.
            ex.printStackTrace();
            StatusPrinter.print(loggerContext);
        }
    }
}
Also used : 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) URL(java.net.URL)

Aggregations

JoranException (ch.qos.logback.core.joran.spi.JoranException)18 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)15 LoggerContext (ch.qos.logback.classic.LoggerContext)12 InputStream (java.io.InputStream)5 URL (java.net.URL)5 File (java.io.File)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ILoggerFactory (org.slf4j.ILoggerFactory)3 IOException (java.io.IOException)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