I'm running Spark on a Yarn cluster and having log4j.properties configured such that all logs by default go to a log file. However, for some spark jobs I want the logs to go to console without changing the log4j file and the code of the actual job. What is the best way to achieve this? Thanks, all.
相关问题
- How to maintain order of key-value in DataFrame sa
- Spark on Yarn Container Failure
- I want to trace logs using a Macro multi parameter
- Error message 'No handlers could be found for
- In Spark Streaming how to process old data and del
相关文章
- Livy Server: return a dataframe as JSON?
- how do I log requests and responses for debugging
- Android Studio doesn't display logs by package
- SQL query Frequency Distribution matrix for produc
- Stacktrace does not print in Glassfish 4.1 Cluster
- Out of curiosity — why don't logging APIs impl
- How to filter rows for a specific aggregate with s
- Laravel log file based on date
I know there have at least 4 solutions for solving this problem.
You could modify your log4j.properties in your Spark machines
When you running the job on spark you better to attach the log4j file as configuration file submit to spark example
bin/spark-submit --class com.viaplay.log4jtest.log4jtest --conf "spark.driver.extraJavaOptions=-Dlog4j.configuration=file:/Users/feng/SparkLog4j/SparkLog4jTest/target/log4j2.properties" --master local[*] /Users/feng/SparkLog4j/SparkLog4jTest/target/SparkLog4jTest-1.0-jar-with-dependencies.jar
Try to import log4j to your logic code.
import org.apache.log4j.Logger; import org.apache.log4j.Level;
put those logger to your SparkContext() function Logger.getLogger("org").setLevel(Level.INFO); Logger.getLogger("akka").setLevel(Level.INFO);
Spark use spark.sql.SparkSession
import org.apache.spark.sql.SparkSession; spark = SparkSession.builder.getOrCreate() spark.sparkContext.setLogLevel('ERROR')
Per the documentation:
upload a custom log4j.properties using spark-submit, by adding it to the --files list of files to be uploaded with the application.
I just tried with a
log4j.properties
file on a Yarn cluster and it works just fine.