Search in sources :

Example 6 with PatternLayoutEncoder

use of org.sonar.process.logging.PatternLayoutEncoder in project sonarqube by SonarSource.

the class CeProcessLoggingTest method log_to_ce_file.

@Test
public void log_to_ce_file() {
    LoggerContext ctx = underTest.configure(props);
    Logger root = ctx.getLogger(Logger.ROOT_LOGGER_NAME);
    Appender<ILoggingEvent> appender = root.getAppender("file_ce");
    assertThat(appender).isInstanceOf(FileAppender.class);
    FileAppender fileAppender = (FileAppender) appender;
    assertThat(fileAppender.getFile()).isEqualTo(new File(logDir, "ce.log").getAbsolutePath());
    assertThat(fileAppender.getEncoder()).isInstanceOf(PatternLayoutEncoder.class);
    PatternLayoutEncoder encoder = (PatternLayoutEncoder) fileAppender.getEncoder();
    assertThat(encoder.getPattern()).isEqualTo("%d{yyyy.MM.dd HH:mm:ss} %-5level ce[%X{ceTaskUuid}][%logger{20}] %msg%n");
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) 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) File(java.io.File) Test(org.junit.Test)

Example 7 with PatternLayoutEncoder

use of org.sonar.process.logging.PatternLayoutEncoder 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

PatternLayoutEncoder (org.sonar.process.logging.PatternLayoutEncoder)7 Logger (ch.qos.logback.classic.Logger)5 LoggerContext (ch.qos.logback.classic.LoggerContext)5 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)5 FileAppender (ch.qos.logback.core.FileAppender)5 Test (org.junit.Test)5 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)3 Appender (ch.qos.logback.core.Appender)2 File (java.io.File)2 OutputStreamAppender (ch.qos.logback.core.OutputStreamAppender)1