I need to output the Spark application name (spark.app.name) in each line of the driver log (along with other attributes like message and date).
So far I failed to find the correct log4j configuration or any other hints.
How could it be done?
I would appreciate any help.
Using Spark standalone mode.
One way that seems to work involves the following two steps:
Create your custom
log4j.propertiesfile and change the layout.:This file must be at the root of your class path (like in
src/main/resourcesfor most build tools) or edit<spark-home>/conf/log4j.propertieson servers in your cluster.Then set a property with the referenced key before bootstrapping your spark context:
In my quick test, the above produces something like this in all lines (tested in local mode):
Instead of setting the variable by hand in code, you may prefer to call
spark-submitwith something likeFor a more permanent change, you may want to edit
<spark-home>/conf/log4j.properties(copy the template if the file doesn't exist) with the layout change, and callspark-submit/spark-shell, etc. with the system property.