Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache Spark custom log4j configuration for application

Tags:

apache-spark

I would like to customize the Log4J configuration for my application in a standalone Spark cluster. I have a log4j.xml file which is inside my application JAR. What is the correct way to get Spark to use that configuration instead of its own Log4J configuration?

I tried using the --conf options to set the following, but no luck.

spark.executor.extraJavaOptions -> -Dlog4j.configuration=log4j.xml
spark.driver.extraJavaOptions -> -Dlog4j.configuration=log4j.xml

I am using Spark 1.4.1 and there's no log4j.properties file in my /conf.

like image 878
Yohan Liyanage Avatar asked Oct 21 '15 14:10

Yohan Liyanage


People also ask

Does Apache Spark uses log4j?

Log4j in Apache SparkSpark uses log4j as the standard library for its own logging.

Is Apache spark vulnerable to log4j?

There is a vulnerability in Apache log4j used by Spark and Zookeeper that is affecting QRadar User Behavior Analytics(UBA). This has been addressed in both dependencies and UBA has been updated to the patched versions.

Where is log4j properties file located Spark?

example-spark/src/main/resources/log4j. properties.


2 Answers

If you are using SBT as package manager/builder:

There is a log4j.properties.template in $SPARK_HOME/conf

  • copy it in your SBT project's src/main/resource
  • remove the .template suffix
  • edit it to fit your needs
  • SBT run/package/* will include this in JAR and Spark references it.

Works for me, and will probably include similar steps for other package managers, e.g. maven.

like image 175
mehmetminanc Avatar answered Oct 14 '22 03:10

mehmetminanc


Try using driver-java-options. For example:

spark-submit --class my.class --master spark://myhost:7077 --driver-java-options "-Dlog4j.configuration=file:///opt/apps/conf/my.log4j.properties" my.jar
like image 34
Patrick McGloin Avatar answered Oct 14 '22 03:10

Patrick McGloin