如何在我的 Spark 应用程序/驱动程序中使用特定的 log4j2.properties 文件?

问题描述 投票:0回答:1

我正在尝试在我的 Spark 应用程序(以及驱动程序中)中使用自定义

log4j2.properties
文件

我的 Spark 版本是最新的:

3.5.0

我按照这个问题的答案,将其适应log4j2

所以基本上我将其添加到

spark-submit

--conf 'spark.driver.extraJavaOptions=-Dlog4j.configurationFile=log4j2.properties'
--conf 'spark.executor.extraJavaOptions=-Dlog4j.configurationFile=log4j2.properties'
--files 'path/to/log4j2.properties'

在驱动程序日志中,我可以看到 JVM 参数:

-Dlog4j.configurationFile=log4j2.properties

但奇怪的是,在日志(stderr)中,我可以看到:

Using Spark's default log4j profile: org/apache/spark/log4j2-defaults.properties
[...]
23/09/29 14:04:08 INFO SparkContext: Added file file:///path/to/log4j2.properties at spark://server:port/files/log4j2.properties with timestamp 1695989047843

记录器初始化后

log4j2.properties
文件被复制,因此,它不起作用,我的文件不被考虑在内。有什么想法吗?

java apache-spark log4j log4j2
1个回答
0
投票
3.3.0

似乎 

Dlog4j.configuration

Dlog4j2.configurationFile
的旧版本,以下语法对我有用:
--files "./shared/code/log4j.properties" \
--conf "spark.driver.extraJavaOptions=-Dlog4j2.configurationFile=file:./shared/code/log4j.properties" \
--conf "spark.executor.extraJavaOptions=-Dlog4j2.configurationFile=file:./shared/code/log4j.properties" \

shared

是docker容器中的一个安装文件夹,我在其中以客户端模式运行spark集群。

    

© www.soinside.com 2019 - 2024. All rights reserved.