Search in sources :

Example 96 with Appender

use of ch.qos.logback.core.Appender in project cuba by cuba-platform.

the class LogControlImpl method getAllAppenders.

protected Map<String, Appender> getAllAppenders() {
    Map<String, Appender> map = new HashMap<>();
    LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
    for (Logger logger : context.getLoggerList()) {
        for (Iterator<Appender<ILoggingEvent>> index = logger.iteratorForAppenders(); index.hasNext(); ) {
            Appender<ILoggingEvent> appender = index.next();
            if (appender.getName() != null) {
                map.put(appender.getName(), appender);
            }
        }
    }
    return map;
}
Also used : Appender(ch.qos.logback.core.Appender) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext)

Example 97 with Appender

use of ch.qos.logback.core.Appender in project sonarqube by SonarSource.

the class WebServerProcessLoggingTest method do_not_log_to_console.

@Test
public void do_not_log_to_console() {
    LoggerContext ctx = underTest.configure(props);
    Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
    Appender appender = root.getAppender("CONSOLE");
    assertThat(appender).isNull();
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) OutputStreamAppender(ch.qos.logback.core.OutputStreamAppender) 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)

Example 98 with Appender

use of ch.qos.logback.core.Appender in project sonarqube by SonarSource.

the class LogbackHelperTest method createRollingPolicy_size.

@Test
public void createRollingPolicy_size() throws Exception {
    props.set("sonar.log.rollingPolicy", "size:1MB");
    props.set("sonar.log.maxFiles", "20");
    LoggerContext ctx = underTest.getRootContext();
    LogbackHelper.RollingPolicy policy = underTest.createRollingPolicy(ctx, props, "sonar");
    Appender appender = policy.createAppender("SONAR_FILE");
    assertThat(appender).isInstanceOf(RollingFileAppender.class);
    // max 20 files of 1Mb
    RollingFileAppender fileAppender = (RollingFileAppender) appender;
    FixedWindowRollingPolicy rollingPolicy = (FixedWindowRollingPolicy) fileAppender.getRollingPolicy();
    assertThat(rollingPolicy.getMaxIndex()).isEqualTo(20);
    assertThat(rollingPolicy.getFileNamePattern()).endsWith("sonar.%i.log");
    SizeBasedTriggeringPolicy triggeringPolicy = (SizeBasedTriggeringPolicy) fileAppender.getTriggeringPolicy();
    FileSize maxFileSize = (FileSize) FieldUtils.readField(triggeringPolicy, "maxFileSize", true);
    assertThat(maxFileSize.getSize()).isEqualTo(1024L * 1024);
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) FixedWindowRollingPolicy(ch.qos.logback.core.rolling.FixedWindowRollingPolicy) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) SizeBasedTriggeringPolicy(ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy) LoggerContext(ch.qos.logback.classic.LoggerContext) FileSize(ch.qos.logback.core.util.FileSize) Test(org.junit.Test)

Example 99 with Appender

use of ch.qos.logback.core.Appender in project sonarqube by SonarSource.

the class LogbackHelperTest method createRollingPolicy_none.

@Test
public void createRollingPolicy_none() {
    props.set("sonar.log.rollingPolicy", "none");
    LoggerContext ctx = underTest.getRootContext();
    LogbackHelper.RollingPolicy policy = underTest.createRollingPolicy(ctx, props, "sonar");
    Appender appender = policy.createAppender("SONAR_FILE");
    assertThat(appender).isNotInstanceOf(RollingFileAppender.class).isInstanceOf(FileAppender.class);
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 100 with Appender

use of ch.qos.logback.core.Appender in project sonarqube by SonarSource.

the class CeProcessLoggingTest method startup_logger_prints_to_only_to_system_out.

@Test
public void startup_logger_prints_to_only_to_system_out() {
    LoggerContext ctx = underTest.configure(props);
    Logger startup = ctx.getLogger("startup");
    assertThat(startup.isAdditive()).isFalse();
    Appender appender = startup.getAppender("CONSOLE");
    assertThat(appender).isInstanceOf(ConsoleAppender.class);
    ConsoleAppender<ILoggingEvent> consoleAppender = (ConsoleAppender<ILoggingEvent>) appender;
    assertThat(consoleAppender.getTarget()).isEqualTo("System.out");
    assertThat(consoleAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class);
    PatternLayoutEncoder patternEncoder = (PatternLayoutEncoder) consoleAppender.getEncoder();
    assertThat(patternEncoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level app[][%logger{20}] %msg%n");
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) FileAppender(ch.qos.logback.core.FileAppender) Appender(ch.qos.logback.core.Appender) ConsoleAppender(ch.qos.logback.core.ConsoleAppender) PatternLayoutEncoder(org.sonar.process.logging.PatternLayoutEncoder) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Aggregations

Appender (ch.qos.logback.core.Appender)118 Test (org.junit.Test)62 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)51 Logger (ch.qos.logback.classic.Logger)32 LoggerContext (ch.qos.logback.classic.LoggerContext)32 FileAppender (ch.qos.logback.core.FileAppender)27 Logger (org.slf4j.Logger)25 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)21 ArgumentMatcher (org.mockito.ArgumentMatcher)19 AsyncAppender (ch.qos.logback.classic.AsyncAppender)18 File (java.io.File)14 OnMarkerEvaluator (ch.qos.logback.classic.boolex.OnMarkerEvaluator)13 EvaluatorFilter (ch.qos.logback.core.filter.EvaluatorFilter)13 LogstashTcpSocketAppender (net.logstash.logback.appender.LogstashTcpSocketAppender)13 ArrayList (java.util.ArrayList)11 ApplicationService (org.codice.ddf.admin.application.service.ApplicationService)11 OutputStreamAppender (ch.qos.logback.core.OutputStreamAppender)10 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)9 DBAppender (ch.qos.logback.classic.db.DBAppender)8 Test (org.junit.jupiter.api.Test)7