環境說明:HDP 3.0 + Kerberos + Livy
根據 Spark 官方文檔的指引,清楚的知道存在三種方式能夠對應用的日誌級別進行調整。html
log4j.properties
using spark-submit
, by adding it to the --files
list of files to be uploaded with the application.-Dlog4j.configuration=<location of configuration file>
to spark.driver.extraJavaOptions
(for the driver) or spark.executor.extraJavaOptions
(for executors). Note that if using a file, the file:
protocol should be explicitly provided, and the file needs to exist locally on all the nodes.$SPARK_CONF_DIR/log4j.properties
file and it will be automatically uploaded along with the other configurations. Note that other 2 options has higher priority than this option if multiple options are specified.第三種方案是咱們最不但願看到的選擇,於是選擇了第1、二兩種進行嘗試。node
過程:apache
log4j-error.properties
文件上傳到 HDFS"files":["/logfile/log4j-error.properties"]
參數,來指定 log4j.properties
文件路徑。"spark.driver.extraJavaOptions": "-Dlog4j.configuration=log4j-error.properties","spark.executor.extraJavaOptions": "-Dlog4j.configuration=log4j-error.properties"
,相對路徑便可這裏的可能遇到的問題:api
-files
參數是數組,不是簡單的 Stringspark.driver.extraJavaOptions
用於 Driver 的日誌級別文件的指定,"spark.executor.extraJavaOptions
用於 Executor 的日誌級別文件的指定。能夠單獨分別指定,支持相對路徑。過程:數組
log4j-error.properties
文件上傳到 Spark Server
所在服務器的 $SPARK_CONF_DIR/
目錄下log4j-error.properties
文件讀取權限,粗暴一點直接設置爲 777"spark.driver.extraJavaOptions": "-Dlog4j.configuration=log4j-error.properties","spark.executor.extraJavaOptions": "-Dlog4j.configuration=log4j-error.properties"
,若是相對路徑不生效,能夠使用絕對路徑( file:/spark/conf/log4j-error.properties
)這裏的可能遇到的問題:服務器
過程:app
HDP Ambari
頁面 Spark 下,對日誌配置進行相應的修改這裏的可能遇到的問題:ide
log4j
配置好比:但願 com.zerostech.demo
路徑下日誌級別爲 ERRORthis
log4j.logger.com.zerostech.demo=ERROR