Class KafkaAccessLogWriter<K,​V>

  • All Implemented Interfaces:
    com.linecorp.armeria.server.logging.AccessLogWriter

    public final class KafkaAccessLogWriter<K,​V>
    extends Object
    implements com.linecorp.armeria.server.logging.AccessLogWriter
    An AccessLogWriter that sends access logs to a Kafka backend.

    This method returns immediately after the Producer.send(ProducerRecord, Callback) returns rather than waiting for returned Future completes so logs which are written and are not yet flushed can be lost if an application crashes in unclean way.

    • Constructor Detail

      • KafkaAccessLogWriter

        public KafkaAccessLogWriter​(Producer<K,​V> producer,
                                    String topic,
                                    Function<? super com.linecorp.armeria.common.logging.RequestLog,​? extends V> valueExtractor)
        Creates a new instance.
        Parameters:
        producer - a Kafka Producer which is used to send logs to Kafka
        topic - the name of topic which is used to send logs
        valueExtractor - a Function that extracts a V-typed record value from a RequestLog. The Function is allowed to return null to skip logging for the given RequestLog.
      • KafkaAccessLogWriter

        public KafkaAccessLogWriter​(Producer<K,​V> producer,
                                    String topic,
                                    Function<? super com.linecorp.armeria.common.logging.RequestLog,​? extends K> keyExtractor,
                                    Function<? super com.linecorp.armeria.common.logging.RequestLog,​? extends V> valueExtractor)
        Creates a new instance.
        Parameters:
        producer - a Kafka Producer which is used to send logs to Kafka
        topic - the name of topic which is used to send logs
        keyExtractor - a Function that extracts a K-typed record key from a RequestLog. The Function is allowed to return null to leave the record key unspecified.
        valueExtractor - a Function that extracts a V-typed record value from a RequestLog. The Function is allowed to return null to skip logging for the given RequestLog.
    • Method Detail

      • log

        public void log​(com.linecorp.armeria.common.logging.RequestLog log)
        Specified by:
        log in interface com.linecorp.armeria.server.logging.AccessLogWriter
      • shutdown

        public CompletableFuture<Void> shutdown()
        Specified by:
        shutdown in interface com.linecorp.armeria.server.logging.AccessLogWriter