談談 Spark 應用日誌級別的坑

環境說明:HDP 3.0 + Kerberos + Livy

根據 Spark 官方文檔的指引,清楚的知道存在三種方式能夠對應用的日誌級別進行調整。html

  • upload a custom log4j.properties using spark-submit, by adding it to the --files list of files to be uploaded with the application.
  • add -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.
  • update the $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

  1. 將編輯準備好的 log4j-error.properties 文件上傳到 HDFS
  2. 授予接下來啓動 Spark 應用的用戶讀取權限
  3. 啓動參數中,添加 "files":["/logfile/log4j-error.properties"] 參數,來指定 log4j.properties 文件路徑。
  4. 啓動參數中,添加 "spark.driver.extraJavaOptions": "-Dlog4j.configuration=log4j-error.properties","spark.executor.extraJavaOptions": "-Dlog4j.configuration=log4j-error.properties" ,相對路徑便可
  5. 使用 Livy 進行啓動應用

這裏的可能遇到的問題:api

  • -files 參數是數組,不是簡單的 String
  • spark.driver.extraJavaOptions 用於 Driver 的日誌級別文件的指定,"spark.executor.extraJavaOptions 用於 Executor 的日誌級別文件的指定。能夠單獨分別指定,支持相對路徑。
  • HDFS 下文件的權限必定要注意

第二種方案

過程:數組

  1. 將編輯準備好的 log4j-error.properties 文件上傳到 Spark Server 所在服務器的 $SPARK_CONF_DIR/ 目錄下
  2. 授予 log4j-error.properties 文件讀取權限,粗暴一點直接設置爲 777
  3. 啓動參數中,添加 "spark.driver.extraJavaOptions": "-Dlog4j.configuration=log4j-error.properties","spark.executor.extraJavaOptions": "-Dlog4j.configuration=log4j-error.properties" ,若是相對路徑不生效,能夠使用絕對路徑( file:/spark/conf/log4j-error.properties )
  4. 使用 Livy 進行啓動應用

這裏的可能遇到的問題:服務器

  • 讀取的權限,必定要啓動應用的用戶擁有權限
  • 全部 Spark 節點下都要有日誌文件哦

第三種方案

過程:app

  1. HDP Ambari 頁面 Spark 下,對日誌配置進行相應的修改
  2. 重啓 Spark 服務使其生效

這裏的可能遇到的問題:ide

  • 優先級該方案是三者中最低的,前兩種均可以覆蓋該種方案

談談 log4j 配置

自定義某路徑下的日誌級別

好比:但願 com.zerostech.demo 路徑下日誌級別爲 ERRORthis

log4j.logger.com.zerostech.demo=ERROR
相關文章
相關標籤/搜索