环境说明: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