Browse Source

KAFKA-323 Add more parameters to the log4j appender. Patch by Jose Quinteiro.

git-svn-id: https://svn.apache.org/repos/asf/incubator/kafka/branches/0.8@1373067 13f79535-47bb-0310-9956-ffa450edef68
0.8.0-beta1-candidate1
Edward Jay Kreps 12 years ago
parent
commit
9eb99fde9a
  1. 23
      core/src/main/scala/kafka/producer/KafkaLog4jAppender.scala

23
core/src/main/scala/kafka/producer/KafkaLog4jAppender.scala

@ -28,7 +28,11 @@ class KafkaLog4jAppender extends AppenderSkeleton with Logging { @@ -28,7 +28,11 @@ class KafkaLog4jAppender extends AppenderSkeleton with Logging {
var topic:String = null
var serializerClass:String = null
var brokerList:String = null
var producerType:String = null
var compressionCodec:String = null
var enqueueTimeout:String = null
var queueSize:String = null
private var producer: Producer[String, String] = null
def getTopic:String = topic
@ -40,6 +44,18 @@ class KafkaLog4jAppender extends AppenderSkeleton with Logging { @@ -40,6 +44,18 @@ class KafkaLog4jAppender extends AppenderSkeleton with Logging {
def getSerializerClass:String = serializerClass
def setSerializerClass(serializerClass:String) { this.serializerClass = serializerClass }
def getProducerType:String = producerType
def setProducerType(producerType:String) { this.producerType = producerType }
def getCompressionCodec:String = compressionCodec
def setCompressionCodec(compressionCodec:String) { this.compressionCodec = compressionCodec }
def getEnqueueTimeout:String = enqueueTimeout
def setEnqueueTimeout(enqueueTimeout:String) { this.enqueueTimeout = enqueueTimeout }
def getQueueSize:String = queueSize
def setQueueSize(queueSize:String) { this.queueSize = queueSize }
override def activateOptions() {
// check for config parameter validity
val props = new Properties()
@ -54,6 +70,11 @@ class KafkaLog4jAppender extends AppenderSkeleton with Logging { @@ -54,6 +70,11 @@ class KafkaLog4jAppender extends AppenderSkeleton with Logging {
LogLog.debug("Using default encoder - kafka.serializer.StringEncoder")
}
props.put("serializer.class", serializerClass)
//These have default values in ProducerConfig and AsyncProducerConfig. We don't care if they're not specified
if(producerType != null) props.put("producer.type", producerType)
if(compressionCodec != null) props.put("compression.codec", compressionCodec)
if(enqueueTimeout != null) props.put("queue.enqueueTimeout.ms", enqueueTimeout)
if(queueSize != null) props.put("queue.size", queueSize)
val config : ProducerConfig = new ProducerConfig(props)
producer = new Producer[String, String](config)
LogLog.debug("Kafka producer connected to " + config.brokerList)

Loading…
Cancel
Save