Kafka Log4j appender not sending messages

牧云@^-^@ 提交于 2019-12-04 16:27:45

I have took a look at the source code of KafkaLog4jAppender.scala and here are the valid and exhaustive properties for Kafka log4j appender as of version 0.8.2.1 : topic, brokerList, compressionType, requiredNumAcks, syncSend.

The log4j.properties that worked for me is below :

log4j.rootLogger=ERROR, stdout

log4j.logger.logGen=DEBUG, KAFKA

log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L %% %m%n

log4j.appender.KAFKA=kafka.producer.KafkaLog4jAppender
log4j.appender.KAFKA.topic=LOG
log4j.appender.KAFKA.brokerList=localhost:9092
log4j.appender.KAFKA.compressionType=none
log4j.appender.KAFKA.requiredNumAcks=0
log4j.appender.KAFKA.syncSend=true
log4j.appender.KAFKA.layout=org.apache.log4j.PatternLayout
log4j.appender.KAFKA.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L %% - %m%n

You need to add KAFKA to your log4j.rootLogger like this:

log4j.rootLogger=INFO, stdout, KAFKA

This will add the KAFKA appender to your rootLogger.

i had to specify

log4j.appender.KAFKA.producer.type=async

log4j.logger.logGen.TestLog4j=TRACE, KAFKA

and that seems to work. however i experience a delay of 10-30 seconds. Specifically, if i publish right now and can see the messages in teh consumer, then the next time i publish has to be about 30 secs later else i dont see anything in my consumer. any ideas on why this might be happening ? maybe its an eclispe issue ?

log4j.appender.KAFKA.SerializerClass=kafka.producer.DefaultStringEncoder

could you try

log4j.appender.KAFKA.Serializer=kafka.producer.DefaultStringEncoder

Instead?

I believe the async mode of sending msgs does so by batching, hence the delay, have you you tried sending using sync?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!