如何在LOG4J2.XML中配置KafkaAppender

时间:2016-03-08 12:20:17

标签: java xml apache-kafka log4j2 appender

我正在尝试使用Kafka 9配置KafkaLog4jAppender提供的log4j2.xml

我的log4j2.xml文件类似于: -

<?xml version="1.0" encoding="UTF-8"?>
<Configuration packages="org.apache.kafka.log4jappender"
    status="INFO">
    <Appenders>
        <Kafka name="Kafka"  topic="log-test">
            <PatternLayout pattern="%date %message" />
            <Property name="bootstrap.servers">localhost:9092</Property>
        </Kafka>
    </Appenders>
    <Loggers>
        <Root level="debug">
            <AppenderRef ref="Kafka" />
        </Root>
        <Logger name="org.apache.kafka" level="INFO" />
    </Loggers>
</Configuration>

我的日志输出是

2016-03-08 12:14:27,480 ERROR Error processing element Kafka: CLASS_NOT_FOUND
2016-03-08 12:14:27,520 ERROR Unable to locate appender Kafka for logger 

如何指定KafkaLog4jAppender的完整班级名称?

我唯一的选择是使用log4j 1吗?

1 个答案:

答案 0 :(得分:0)

通过Apache Log4j 2.5

解决了此问题