【发布时间】:2019-11-15 01:20:45
【问题描述】:
我的 IDE 中有多个 spark 项目。默认情况下,spark 会在 spark/conf 文件夹中选择 log4j.properties 文件。
由于我有多个 spark 项目,我想要多个 log4j.properties 文件(每个项目一个)。可能作为项目代码的一部分(资源文件夹)
有没有办法我们可以获取指定的 log4j.properries 而不是默认的 log4j.properties。
注意: 我试过这个
--driver-java-options "-Dlog4j.configuration=file:///usr/local/Cellar/apache-spark/2.4.1/libexec/conf/driver_log4j.properties"
它没有任何问题,但是我正在寻找类似下面的东西。
但是我想在创建 spark 记录器时加载资源文件夹中的 log4j.properties 文件。
class SparkLogger():
def __init__(self, app_name, sparksession = None):
self._spark = sparksession
self.log4jLogger = None
if self._spark is not None:
sparkContext =self._spark.sparkContext
self.log4jLogger = sparkContext._jvm.org.apache.log4j
self.log4jLogger = self.log4jLogger.LogManager.getLogger(app_name)
def info(self, info):
if self.log4jLogger:
self.log4jLogger.info(str(info))
def error(self, info):
if self.log4jLogger:
self.log4jLogger.error(str(info))
def warn(self, info):
if self.log4jLogger:
self.log4jLogger.warn(str(info))
def debug(self, info):
if self.log4jLogger:
self.log4jLogger.debug(str(info))
【问题讨论】:
标签: apache-spark logging pyspark log4j