Search in sources :

Example 1 with BasicConfigurator

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

the class ConfigFileApplicationListenerTests method resetLogging.

@Before
public void resetLogging() {
    LoggerContext loggerContext = ((Logger) LoggerFactory.getLogger(getClass())).getLoggerContext();
    loggerContext.reset();
    new BasicConfigurator().configure(loggerContext);
}
Also used : BasicConfigurator(ch.qos.logback.classic.BasicConfigurator) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) Before(org.junit.Before)

Example 2 with BasicConfigurator

use of ch.qos.logback.classic.BasicConfigurator 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)

Example 3 with BasicConfigurator

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

the class SpringBootJoranConfiguratorTests method reset.

@After
public void reset() {
    this.context.stop();
    new BasicConfigurator().configure((LoggerContext) LoggerFactory.getILoggerFactory());
}
Also used : BasicConfigurator(ch.qos.logback.classic.BasicConfigurator) After(org.junit.After)

Aggregations

BasicConfigurator (ch.qos.logback.classic.BasicConfigurator)3 Logger (ch.qos.logback.classic.Logger)1 LoggerContext (ch.qos.logback.classic.LoggerContext)1 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)1 JoranException (ch.qos.logback.core.joran.spi.JoranException)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 After (org.junit.After)1 Before (org.junit.Before)1