为kafka java应用程序配置log4j

vmdwslir  于 2021-06-08  发布在  Kafka
关注(0)|答案(1)|浏览(398)

我正在尝试从java应用程序连接到kafka,当我启动该应用程序时,在stdout上收到以下消息:

log4j:WARN No such property [host] in kafka.producer.KafkaLog4jAppender.
log4j:WARN No such property [serializer] in kafka.producer.KafkaLog4jAppender.
log4j:WARN No such property [port] in kafka.producer.KafkaLog4jAppender.

以下是官方快速入门中提供的log4.properties:

// define the kafka log4j appender config parameters
log4j.appender.KAFKA=kafka.producer.KafkaLog4jAppender
// REQUIRED: set the hostname of the kafka server
log4j.appender.KAFKA.Host=hadoop-server
// REQUIRED: set the port on which the Kafka server is listening for connections
log4j.appender.KAFKA.Port=9092
// REQUIRED: the topic under which the logger messages are to be posted
log4j.appender.KAFKA.Topic=test
// the serializer to be used to turn an object into a Kafka message. Defaults to kafka.producer.DefaultStringEncoder
log4j.appender.KAFKA.Serializer=kafka.test.AppenderStringSerializer
// do not set the above KAFKA appender as the root appender
log4j.rootLogger=INFO
// set the logger for your package to be the KAFKA appender

我错过了什么?我该怎么修?

hrirmatl

hrirmatl1#

用Kafka0.8代替

log4j.appender.KAFKA.Host=hadoop-server
log4j.appender.KAFKA.Port=9092

尝试指定代理列表,如

log4j.appender.KAFKA.BrokerList=host1:9092,host2:9092

此外,serializer属性已更改为serializerclass

log4j.appender.KAFKA.SerializerClass=kafka.test.AppenderStringSerializer

相关问题