Search in sources :

Example 1 with KieSiftingAppender

use of org.kie.workbench.common.services.backend.logback.appender.KieSiftingAppender 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)

Example 2 with KieSiftingAppender

use of org.kie.workbench.common.services.backend.logback.appender.KieSiftingAppender in project kie-wb-common by kiegroup.

the class LogbackConfig method setSiftingAppender.

private SiftingAppender setSiftingAppender(LoggerContext loggerContext, Discriminator discriminator) {
    KieSiftingAppender appender = new KieSiftingAppender();
    appender.setName(MavenConfig.COMPILATION_ID);
    appender.setDiscriminator(discriminator);
    appender.setAppenderFactory(new AppenderFactory<ILoggingEvent>() {

        @Override
        public Appender<ILoggingEvent> buildAppender(Context context, String discriminatingValue) throws JoranException {
            KieSiftingAppender kieAppender = new KieSiftingAppender();
            kieAppender.setName(discriminatingValue);
            kieAppender.setContext(loggerContext);
            return kieAppender;
        }
    });
    appender.setContext(loggerContext);
    appender.start();
    return appender;
}
Also used : Context(ch.qos.logback.core.Context) LoggerContext(ch.qos.logback.classic.LoggerContext) ConsoleAppender(ch.qos.logback.core.ConsoleAppender) KieSiftingAppender(org.kie.workbench.common.services.backend.logback.appender.KieSiftingAppender) Appender(ch.qos.logback.core.Appender) SiftingAppender(ch.qos.logback.classic.sift.SiftingAppender) JoranException(ch.qos.logback.core.joran.spi.JoranException) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) KieSiftingAppender(org.kie.workbench.common.services.backend.logback.appender.KieSiftingAppender)

Aggregations

ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)2 ConsoleAppender (ch.qos.logback.core.ConsoleAppender)2 KieSiftingAppender (org.kie.workbench.common.services.backend.logback.appender.KieSiftingAppender)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 PatternLayoutEncoder (ch.qos.logback.classic.encoder.PatternLayoutEncoder)1 SiftingAppender (ch.qos.logback.classic.sift.SiftingAppender)1 Appender (ch.qos.logback.core.Appender)1 Context (ch.qos.logback.core.Context)1 Encoder (ch.qos.logback.core.encoder.Encoder)1 JoranException (ch.qos.logback.core.joran.spi.JoranException)1 Test (org.junit.Test)1