Configure Apache Log4j2 properties for Amazon EMR Serverless
This page describes how to configure custom Apache Log4j 2.xStartJobRun
. If you want to configure Log4j
classifications at the application level, see Default application configuration for EMR Serverless.
Configure Spark Log4j2 properties for Amazon EMR Serverless
With Amazon EMR releases 6.8.0 and higher, you can customize Apache Log4j 2.xspark-driver-log4j2
and spark-executor-log4j2
classifications.
Topics
Log4j2 classifications for Spark
To customize the Spark log configurations, use the following classifications
with applicationConfiguration
. To configure the Log4j
2.x properties, use the following properties
.
spark-driver-log4j2
-
This classification sets the values in the
log4j2.properties
file for the driver. spark-executor-log4j2
-
This classification sets the values in the
log4j2.properties
file for the executor.
Log4j2 configuration example for Spark
The following example shows how to submit a Spark job with
applicationConfiguration
to customize Log4j2 configurations for
the Spark driver and executor.
To configure Log4j classifications at the application level instead of when you submit the job, see Default application configuration for EMR Serverless.
aws emr-serverless start-job-run \ --application-id application-id \ --execution-role-arn job-role-arn \ --job-driver '{ "sparkSubmit": { "entryPoint": "/usr/lib/spark/examples/jars/spark-examples.jar", "entryPointArguments": ["1"], "sparkSubmitParameters": "--class org.apache.spark.examples.SparkPi --conf spark.executor.cores=4 --conf spark.executor.memory=20g --conf spark.driver.cores=4 --conf spark.driver.memory=8g --conf spark.executor.instances=1" } }' --configuration-overrides '{ "applicationConfiguration": [ { "classification": "spark-driver-log4j2", "properties": { "rootLogger.level":"error", // will only display Spark error logs "logger.
IdentifierForClass
.name": "classpath for setting logger
", "logger.IdentifierForClass
.level": "info" } }, { "classification": "spark-executor-log4j2", "properties": { "rootLogger.level":"error", // will only display Spark error logs "logger.IdentifierForClass
.name": "classpath for setting logger
", "logger.IdentifierForClass
.level": "info" } } ] }'
Log4j2 in sample Spark jobs
The following code samples demonstrate how to create a Spark application while you initialize a custom Log4j2 configuration for the application.
Log4j2 considerations for Spark
The following Log4j2.x properties are not configurable for Spark processes:
-
rootLogger.appenderRef.stdout.ref
-
appender.console.type
-
appender.console.name
-
appender.console.target
-
appender.console.layout.type
-
appender.console.layout.pattern
For detailed information about the Log4j2.x properties that you can configure,
see the log4j2.properties.template
file