I\'m trying to use custom log4j appender inside spark executor, in order to forward all logs to Apache Kafka.
The problem is, log4j is initialized before fatjar\'s c
Ended up submitting extra jar with logging deps and loading it before user classpath.
LOG_JAR="${THISDIR}/../lib/logging.jar"
spark-submit ...... \
--files "${LOG4J_CONF},${LOG_JAR}" \
--conf "spark.driver.extraJavaOptions=-Dlog4j.configuration=`basename ${LOG4J_CONF}`" \
--conf "spark.driver.extraClassPath=`basename ${LOG_JAR}`" \
--conf "spark.executor.extraJavaOptions=-Dlog4j.configuration=`basename ${LOG4J_CONF}`" \
--conf "spark.executor.extraClassPath=`basename ${LOG_JAR}`" \
...
https://issues.apache.org/jira/browse/SPARK-10881?filter=-2
Was facing the same issue , I will post what worked for me, it turns out the KafkaLog4jAppender
class package name changed in kafka 0.9, here is what I did, added following dependency in pom
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>kafka-log4j-appender</artifactId>
<version>0.9.0.0</version>
</dependency>
and changed my log4j.properties from
log4j.appender.KAFKA=kafka.producer.KafkaLog4jAppender
to
log4j.appender.KAFKA=org.apache.kafka.log4jappender.KafkaLog4jAppender
kafka.producer.KafkaLog4jAppender
is in kafka's hadoop-producer.
so you can add this dependency to fix it.
<dependency>
<groupId>org.apache.kafka</groupId>
<artifactId>hadoop-producer</artifactId>
<version>0.8.0</version>
</dependency>