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");
}
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;
}
Aggregations