Search in sources :

Example 16 with PatternLayoutEncoder

use of ch.qos.logback.classic.encoder.PatternLayoutEncoder in project coffeenet-starter by coffeenet.

the class CoffeeNetLoggingAutoConfigurationTest method integration.

@Test
public void integration() {
    final Logger logger = (Logger) LoggerFactory.getLogger(ROOT_LOGGER_NAME);
    assertThat(logger.getAppender("CONSOLE"), is(instanceOf(ConsoleAppender.class)));
    Appender<ILoggingEvent> fileAppender = logger.getAppender("COFFEENET-FILE");
    assertThat(fileAppender, is(instanceOf(RollingFileAppender.class)));
    // Check File Appender
    RollingFileAppender rollingFileAppender = (RollingFileAppender) fileAppender;
    assertThat(rollingFileAppender.getFile(), is("logs/app.log"));
    assertThat(rollingFileAppender.getName(), is("COFFEENET-FILE"));
    RollingPolicy rollingPolicy = rollingFileAppender.getRollingPolicy();
    assertThat(rollingPolicy, is(instanceOf(TimeBasedRollingPolicy.class)));
    TimeBasedRollingPolicy timeBasedRollingPolicy = (TimeBasedRollingPolicy) rollingFileAppender.getRollingPolicy();
    assertThat(timeBasedRollingPolicy.getFileNamePattern(), is("logs/app-%d{yyyy-MM-dd}.log"));
    PatternLayoutEncoder encoder = (PatternLayoutEncoder) rollingFileAppender.getEncoder();
    assertThat(encoder.getPattern(), is("%d{yyyy-MM-dd HH:mm:ss.SSS} %5p --- [%t] %-40.40logger{39} : %m%n%wEx"));
    // Check Gelf Appender
    Appender<ILoggingEvent> gelfAppender = logger.getAppender("COFFEENET-GELF");
    assertThat(gelfAppender, is(instanceOf(GelfAppender.class)));
    GelfAppender gelfAppender1 = (GelfAppender) gelfAppender;
    assertThat(gelfAppender1.getName(), is("COFFEENET-GELF"));
    assertThat(gelfAppender1.getServer(), is("localServer"));
    assertThat(gelfAppender1.getProtocol(), is("TCP"));
    assertThat(gelfAppender1.getPort(), is(1337));
    assertThat(((PatternLayout) gelfAppender1.getLayout()).getPattern(), is("%m"));
    assertThat(gelfAppender1.getAdditionalFields(), hasEntry("environment", "test"));
    assertThat(gelfAppender1.getAdditionalFields(), hasEntry("application", "CoffeeNetApplication"));
}
Also used : PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) GelfAppender(de.appelgriepsch.logback.GelfAppender) RollingPolicy(ch.qos.logback.core.rolling.RollingPolicy) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy) Logger(ch.qos.logback.classic.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 17 with PatternLayoutEncoder

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

the class LogbackHelper method newConsoleAppender.

/**
   * Creates a new {@link ConsoleAppender} to {@code System.out} with the specified name and log pattern.
   *
   * @see #buildLogPattern(RootLoggerConfig)
   */
public ConsoleAppender<ILoggingEvent> newConsoleAppender(Context loggerContext, String name, String logPattern) {
    PatternLayoutEncoder consoleEncoder = new PatternLayoutEncoder();
    consoleEncoder.setContext(loggerContext);
    consoleEncoder.setPattern(logPattern);
    consoleEncoder.start();
    ConsoleAppender<ILoggingEvent> consoleAppender = new ConsoleAppender<>();
    consoleAppender.setContext(loggerContext);
    consoleAppender.setEncoder(consoleEncoder);
    consoleAppender.setName(name);
    consoleAppender.setTarget("System.out");
    consoleAppender.start();
    return consoleAppender;
}
Also used : PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) ConsoleAppender(ch.qos.logback.core.ConsoleAppender) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent)

Example 18 with PatternLayoutEncoder

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

the class SearchLoggingTest method log_to_es_file.

@Test
public void log_to_es_file() {
    LoggerContext ctx = underTest.configure(props);
    Logger root = ctx.getLogger(ROOT_LOGGER_NAME);
    Appender<ILoggingEvent> appender = root.getAppender("file_es");
    assertThat(appender).isInstanceOf(FileAppender.class);
    FileAppender fileAppender = (FileAppender) appender;
    assertThat(fileAppender.getFile()).isEqualTo(new File(logDir, "es.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 es[][%logger{20}] %msg%n");
}
Also used : FileAppender(ch.qos.logback.core.FileAppender) PatternLayoutEncoder(ch.qos.logback.classic.encoder.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 19 with PatternLayoutEncoder

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

the class LogbackHelperTest method newConsoleAppender.

@Test
public void newConsoleAppender() {
    LoggerContext ctx = underTest.getRootContext();
    ConsoleAppender<?> appender = underTest.newConsoleAppender(ctx, "MY_APPENDER", "%msg%n");
    assertThat(appender.getName()).isEqualTo("MY_APPENDER");
    assertThat(appender.getContext()).isSameAs(ctx);
    assertThat(appender.isStarted()).isTrue();
    assertThat(((PatternLayoutEncoder) appender.getEncoder()).getPattern()).isEqualTo("%msg%n");
    assertThat(appender.getCopyOfAttachedFiltersList()).isEmpty();
}
Also used : PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) LoggerContext(ch.qos.logback.classic.LoggerContext) Test(org.junit.Test)

Example 20 with PatternLayoutEncoder

use of ch.qos.logback.classic.encoder.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(ch.qos.logback.classic.encoder.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 (ch.qos.logback.classic.encoder.PatternLayoutEncoder)28 LoggerContext (ch.qos.logback.classic.LoggerContext)19 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)19 Logger (ch.qos.logback.classic.Logger)12 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)9 Test (org.junit.Test)9 FileAppender (ch.qos.logback.core.FileAppender)8 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)7 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)7 File (java.io.File)5 FixedWindowRollingPolicy (ch.qos.logback.core.rolling.FixedWindowRollingPolicy)3 JoranConfigurator (ch.qos.logback.classic.joran.JoranConfigurator)2 Appender (ch.qos.logback.core.Appender)2 SizeBasedTriggeringPolicy (ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy)2 Logger (org.slf4j.Logger)2 RollingPolicy (ch.qos.logback.core.rolling.RollingPolicy)1 BroadcastSession (com.cgbystrom.sockjs.test.BroadcastSession)1 JmxReporter (com.codahale.metrics.JmxReporter)1 MetricRegistry (com.codahale.metrics.MetricRegistry)1 GelfAppender (de.appelgriepsch.logback.GelfAppender)1