Search in sources :

Example 26 with LoggerContext

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

the class LogbackHelperTest method createRollingPolicy_defaults.

@Test
public void createRollingPolicy_defaults() {
    LoggerContext ctx = underTest.getRootContext();
    LogbackHelper.RollingPolicy policy = underTest.createRollingPolicy(ctx, props, "sonar");
    FileAppender appender = policy.createAppender("SONAR_FILE");
    assertThat(appender).isInstanceOf(RollingFileAppender.class);
    // max 5 daily files
    RollingFileAppender fileAppender = (RollingFileAppender) appender;
    TimeBasedRollingPolicy triggeringPolicy = (TimeBasedRollingPolicy) fileAppender.getTriggeringPolicy();
    assertThat(triggeringPolicy.getMaxHistory()).isEqualTo(7);
    assertThat(triggeringPolicy.getFileNamePattern()).endsWith("sonar.%d{yyyy-MM-dd}.log");
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) LoggerContext(ch.qos.logback.classic.LoggerContext) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy) Test(org.junit.Test)

Example 27 with LoggerContext

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

the class LogbackHelperTest method apply_sets_logger_to_INFO_if_no_property_is_set.

@Test
public void apply_sets_logger_to_INFO_if_no_property_is_set() {
    LogLevelConfig config = LogLevelConfig.newBuilder().rootLevelFor(ProcessId.WEB_SERVER).build();
    LoggerContext context = underTest.apply(config, props);
    assertThat(context.getLogger(ROOT_LOGGER_NAME).getLevel()).isEqualTo(Level.INFO);
}
Also used : LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 28 with LoggerContext

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

the class LogbackHelperTest method enableJulChangePropagation.

@Test
public void enableJulChangePropagation() {
    LoggerContext ctx = underTest.getRootContext();
    int countListeners = ctx.getCopyOfListenerList().size();
    LoggerContextListener propagator = underTest.enableJulChangePropagation(ctx);
    assertThat(ctx.getCopyOfListenerList().size()).isEqualTo(countListeners + 1);
    ctx.removeListener(propagator);
}
Also used : LoggerContextListener(ch.qos.logback.classic.spi.LoggerContextListener) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 29 with LoggerContext

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

the class SearchLogging method configure.

public LoggerContext configure(Props props) {
    LoggerContext ctx = helper.getRootContext();
    ctx.reset();
    RootLoggerConfig config = newRootLoggerConfigBuilder().setProcessId(ProcessId.ELASTICSEARCH).build();
    String logPattern = helper.buildLogPattern(config);
    helper.configureGlobalFileLog(props, config, logPattern);
    helper.configureForSubprocessGobbler(props, logPattern);
    helper.apply(LogLevelConfig.newBuilder().rootLevelFor(ProcessId.ELASTICSEARCH).build(), props);
    return ctx;
}
Also used : RootLoggerConfig(org.sonar.process.logging.RootLoggerConfig) LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 30 with LoggerContext

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

the class SearchLoggingTest method do_not_log_to_console.

@Test
public void do_not_log_to_console() {
    LoggerContext ctx = underTest.configure(props);
    Logger root = ctx.getLogger(ROOT_LOGGER_NAME);
    Appender appender = root.getAppender("CONSOLE");
    assertThat(appender).isNull();
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) Logger(ch.qos.logback.classic.Logger) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

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