ch.qos.logback.core.status.StatusListener Java Examples

The following examples show how to use ch.qos.logback.core.status.StatusListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KonkerLoggerContext.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
private void resetStatusListeners() {
    StatusManager sm = this.getStatusManager();
    Iterator i$ = sm.getCopyOfStatusListenerList().iterator();

    while(i$.hasNext()) {
        StatusListener sl = (StatusListener)i$.next();
        sm.remove(sl);
    }

}
 
Example #2
Source File: KonkerStatusListenerConfigHelper.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
private static void addStatusListener(KonkerLoggerContext loggerContext, String listenerClass) {
    Object listener = null;
    if("SYSOUT".equalsIgnoreCase(listenerClass)) {
        listener = new OnConsoleStatusListener();
    } else {
        listener = createListenerPerClassName(loggerContext, listenerClass);
    }

    initAndAddListener(loggerContext, (StatusListener)listener);
}
 
Example #3
Source File: KonkerStatusListenerConfigHelper.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
private static void initAndAddListener(KonkerLoggerContext loggerContext, StatusListener listener) {
    if(listener != null) {
        if(listener instanceof ContextAware) {
            ((ContextAware)listener).setContext(loggerContext);
        }

        if(listener instanceof LifeCycle) {
            ((LifeCycle)listener).start();
        }

        loggerContext.getStatusManager().add(listener);
    }

}
 
Example #4
Source File: KonkerStatusListenerConfigHelper.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
private static StatusListener createListenerPerClassName(KonkerLoggerContext loggerContext,
                                                         String listenerClass) {
    try {
        return (StatusListener)OptionHelper.instantiateByClassName(listenerClass, StatusListener.class, loggerContext);
    } catch (Exception var3) {
        var3.printStackTrace();
        return null;
    }
}
 
Example #5
Source File: KafkaAppenderIT.java    From logback-kafka-appender with Apache License 2.0 4 votes vote down vote up
@Before
public void beforeLogSystemInit() throws IOException, InterruptedException {

    kafka = TestKafka.createTestKafka(1,1,1);

    loggerContext = new LoggerContext();
    loggerContext.putProperty("brokers.list", kafka.getBrokerList());
    loggerContext.getStatusManager().add(new StatusListener() {
        @Override
        public void addStatusEvent(Status status) {
            if (status.getEffectiveLevel() > Status.INFO) {
                System.err.println(status.toString());
                if (status.getThrowable() != null) {
                    collector.addError(status.getThrowable());
                } else {
                    collector.addError(new RuntimeException("StatusManager reported warning: "+status.toString()));
                }
            } else {
                System.out.println(status.toString());
            }
        }
    });
    loggerContext.putProperty("HOSTNAME","localhost");

    unit = new KafkaAppender<>();
    final PatternLayoutEncoder patternLayoutEncoder = new PatternLayoutEncoder();
    patternLayoutEncoder.setPattern("%msg");
    patternLayoutEncoder.setContext(loggerContext);
    patternLayoutEncoder.setCharset(Charset.forName("UTF-8"));
    patternLayoutEncoder.start();
    unit.setEncoder(patternLayoutEncoder);
    unit.setTopic("logs");
    unit.setName("TestKafkaAppender");
    unit.setContext(loggerContext);
    unit.setKeyingStrategy(new NoKeyKeyingStrategy());
    unit.setDeliveryStrategy(new AsynchronousDeliveryStrategy());
    unit.addAppender(fallbackAppender);
    unit.addProducerConfigValue(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, kafka.getBrokerList());
    unit.addProducerConfigValue(ProducerConfig.ACKS_CONFIG, "1");
    unit.addProducerConfigValue(ProducerConfig.MAX_BLOCK_MS_CONFIG, "2000");
    unit.addProducerConfigValue(ProducerConfig.LINGER_MS_CONFIG, "100");
    unit.setPartition(0);
    unit.setDeliveryStrategy(new AsynchronousDeliveryStrategy());
    unit.addAppender(new AppenderBase<ILoggingEvent>() {
        @Override
        protected void append(ILoggingEvent eventObject) {
            fallbackLoggingEvents.add(eventObject);
        }
    });
}