Search in sources :

Example 21 with LoggerContext

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

the class LogbackHelper method apply.

/**
   * Applies the specified {@link LogLevelConfig} reading the specified {@link Props}.
   *
   * @throws IllegalArgumentException if the any level specified in a property is not one of {@link #ALLOWED_ROOT_LOG_LEVELS}
   */
public LoggerContext apply(LogLevelConfig logLevelConfig, Props props) {
    LoggerContext rootContext = getRootContext();
    logLevelConfig.getConfiguredByProperties().entrySet().forEach(entry -> applyLevelByProperty(props, rootContext.getLogger(entry.getKey()), entry.getValue()));
    logLevelConfig.getConfiguredByHardcodedLevel().entrySet().forEach(entry -> applyHardcodedLevel(rootContext, entry.getKey(), entry.getValue()));
    return rootContext;
}
Also used : LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 22 with LoggerContext

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

the class LogbackHelper method changeRoot.

public void changeRoot(LogLevelConfig logLevelConfig, Level newLevel) {
    ensureSupportedLevel(newLevel);
    LoggerContext rootContext = getRootContext();
    rootContext.getLogger(ROOT_LOGGER_NAME).setLevel(newLevel);
    logLevelConfig.getConfiguredByProperties().entrySet().forEach(entry -> rootContext.getLogger(entry.getKey()).setLevel(newLevel));
}
Also used : LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 23 with LoggerContext

use of ch.qos.logback.classic.LoggerContext 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 24 with LoggerContext

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

the class SearchLoggingTest method root_logger_level_changes_with_es_property.

@Test
public void root_logger_level_changes_with_es_property() {
    props.set("sonar.log.level.es", "TRACE");
    LoggerContext ctx = underTest.configure(props);
    verifyRootLogLevel(ctx, Level.TRACE);
}
Also used : LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 25 with LoggerContext

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

the class ServerProcessLogging method configure.

public LoggerContext configure(Props props) {
    LoggerContext ctx = helper.getRootContext();
    ctx.reset();
    helper.enableJulChangePropagation(ctx);
    configureRootLogger(props);
    helper.apply(logLevelConfig, props);
    configureDirectToConsoleLoggers(ctx, STARTUP_LOGGER_NAME);
    extendConfigure();
    return ctx;
}
Also used : LoggerContext(ch.qos.logback.classic.LoggerContext)

Aggregations

LoggerContext (ch.qos.logback.classic.LoggerContext)200 Test (org.junit.Test)133 Logger (ch.qos.logback.classic.Logger)39 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)39 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)21 FileAppender (ch.qos.logback.core.FileAppender)19 File (java.io.File)18 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)15 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)15 Appender (ch.qos.logback.core.Appender)14 NullLevelFilterFactory (io.dropwizard.logging.filter.NullLevelFilterFactory)13 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)12 AsyncLoggingEventAppenderFactory (io.dropwizard.logging.async.AsyncLoggingEventAppenderFactory)12 AsyncAppender (ch.qos.logback.classic.AsyncAppender)11 DropwizardLayoutFactory (io.dropwizard.logging.layout.DropwizardLayoutFactory)11 JoranException (ch.qos.logback.core.joran.spi.JoranException)10 IOException (java.io.IOException)7 Logger (org.slf4j.Logger)7 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)6 ArrayList (java.util.ArrayList)6