Search in sources :

Example 1 with Encoder

use of ch.qos.logback.core.encoder.Encoder in project qpid-broker-j by apache.

the class AppenderUtilsTest method testCreateRollingFileAppenderNonDailyRolling.

@Test
public void testCreateRollingFileAppenderNonDailyRolling() {
    when(_settings.isRollDaily()).thenReturn(Boolean.FALSE);
    when(_settings.isCompressOldFiles()).thenReturn(Boolean.FALSE);
    RollingFileAppender<ILoggingEvent> appender = new RollingFileAppender<>();
    AppenderUtils.configureRollingFileAppender(_settings, new LoggerContext(), appender);
    assertEquals("Unexpected appender file name", _testLogFileName, appender.getFile());
    RollingPolicy rollingPolicy = appender.getRollingPolicy();
    final boolean condition2 = rollingPolicy instanceof RollingPolicyDecorator;
    assertTrue("Unexpected rolling policy", condition2);
    rollingPolicy = ((RollingPolicyDecorator) rollingPolicy).getDecorated();
    final boolean condition1 = rollingPolicy instanceof AppenderUtils.SimpleRollingPolicy;
    assertTrue("Unexpected decorated rolling policy", condition1);
    assertEquals("Unexpected max history", (long) MAX_HISTORY, (long) ((AppenderUtils.SimpleRollingPolicy) rollingPolicy).getMaxIndex());
    assertEquals("Unexpected file name pattern", _testLogFileName + ".%i", ((AppenderUtils.SimpleRollingPolicy) rollingPolicy).getFileNamePattern());
    assertEquals("Unexpected compression mode", CompressionMode.NONE, rollingPolicy.getCompressionMode());
    TriggeringPolicy triggeringPolicy = appender.getTriggeringPolicy();
    assertEquals("Unexpected triggering policy", String.valueOf(MAX_FILE_SIZE) + " MB", ((AppenderUtils.SizeTriggeringPolicy) triggeringPolicy).getMaxFileSize().toString());
    Encoder encoder = appender.getEncoder();
    final boolean condition = encoder instanceof PatternLayoutEncoder;
    assertTrue("Unexpected encoder", condition);
    assertEquals("Unexpected layout pattern", LAYOUT, ((PatternLayoutEncoder) encoder).getPattern());
}
Also used : PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) RollingFileAppender(ch.qos.logback.core.rolling.RollingFileAppender) RollingPolicy(ch.qos.logback.core.rolling.RollingPolicy) TimeBasedRollingPolicy(ch.qos.logback.core.rolling.TimeBasedRollingPolicy) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) TriggeringPolicy(ch.qos.logback.core.rolling.TriggeringPolicy) PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) Encoder(ch.qos.logback.core.encoder.Encoder) Test(org.junit.Test)

Example 2 with Encoder

use of ch.qos.logback.core.encoder.Encoder in project kie-wb-common by kiegroup.

the class LogbackConfigTest method configureLoggingProgrammatically.

@Test
public void configureLoggingProgrammatically() {
    ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME);
    LogbackConfig config = new LogbackConfig();
    config.configure(loggerContext);
    root.info("test appender");
    Appender<ILoggingEvent> kieSift = root.getAppender("KieSift");
    assertThat(kieSift).isNotNull();
    KieSiftingAppender kieSiftAppender = (KieSiftingAppender) kieSift;
    assertThat(kieSiftAppender).isNotNull();
    assertThat(kieSiftAppender.getDiscriminator()).isNotNull();
    assertThat(MavenConfig.COMPILATION_ID).isEqualTo(kieSiftAppender.getDiscriminatorKey());
    Appender<ILoggingEvent> consoleAppenderGeneric = root.getAppender("consoleAppender");
    ConsoleAppender consoleAppender = (ConsoleAppender) consoleAppenderGeneric;
    assertThat(consoleAppender).isNotNull();
    Encoder enc = consoleAppender.getEncoder();
    PatternLayoutEncoder encoder = (PatternLayoutEncoder) enc;
    assertThat(encoder.getPattern()).isEqualTo("%d [%thread] %level %logger{35} - %msg%n");
}
Also used : ConsoleAppender(ch.qos.logback.core.ConsoleAppender) PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) KieSiftingAppender(org.kie.workbench.common.services.backend.logback.appender.KieSiftingAppender) PatternLayoutEncoder(ch.qos.logback.classic.encoder.PatternLayoutEncoder) Encoder(ch.qos.logback.core.encoder.Encoder) Test(org.junit.Test)

Aggregations

PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)2 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)2 Encoder (ch.qos.logback.core.encoder.Encoder)2 Test (org.junit.Test)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)1 RollingFileAppender (ch.qos.logback.core.rolling.RollingFileAppender)1 RollingPolicy (ch.qos.logback.core.rolling.RollingPolicy)1 TimeBasedRollingPolicy (ch.qos.logback.core.rolling.TimeBasedRollingPolicy)1 TriggeringPolicy (ch.qos.logback.core.rolling.TriggeringPolicy)1 KieSiftingAppender (org.kie.workbench.common.services.backend.logback.appender.KieSiftingAppender)1