Class KafkaAccessLogWriter<K,V>

java.lang.Object
com.linecorp.armeria.server.logging.kafka.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 Summary

    Constructors
    Constructor
    Description
    KafkaAccessLogWriter(org.apache.kafka.clients.producer.Producer<K,V> producer, String topic, Function<? super com.linecorp.armeria.common.logging.RequestLog,? extends @Nullable K> keyExtractor, Function<? super com.linecorp.armeria.common.logging.RequestLog,? extends @Nullable V> valueExtractor)
    Creates a new instance.
    KafkaAccessLogWriter(org.apache.kafka.clients.producer.Producer<K,V> producer, String topic, Function<? super com.linecorp.armeria.common.logging.RequestLog,? extends @Nullable V> valueExtractor)
    Creates a new instance.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    log(com.linecorp.armeria.common.logging.RequestLog log)
     
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.linecorp.armeria.server.logging.AccessLogWriter

    andThen
  • Constructor Details

    • KafkaAccessLogWriter

      public KafkaAccessLogWriter(org.apache.kafka.clients.producer.Producer<K,V> producer, String topic, Function<? super com.linecorp.armeria.common.logging.RequestLog,? extends @Nullable 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(org.apache.kafka.clients.producer.Producer<K,V> producer, String topic, Function<? super com.linecorp.armeria.common.logging.RequestLog,? extends @Nullable K> keyExtractor, Function<? super com.linecorp.armeria.common.logging.RequestLog,? extends @Nullable 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 Details

    • 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