通过python sript关闭pyspark日志记录

时间:2017-11-09 14:27:35

标签: apache-spark pyspark

如何从python脚本关闭pyspark日志记录? 请注意:我不想在spark logger属性文件中进行任何更改。

1 个答案:

答案 0 :(得分:2)

从python脚本中删除(或修改)日志记录:

conf = SparkConf()
conf.set('spark.logConf', 'true')  # necessary in order to be able to change log level
... # other stuff and configuration

# create the session
spark = SparkSession.builder\
    .config(conf=conf) \
    .appName(app_name) \
    .getOrCreate()

# set the log level to one of ALL, DEBUG, ERROR, FATAL, INFO, OFF, TRACE, WARN
spark.sparkContext.setLogLevel("OFF")

docs configuration

docs setLogLevel

希望这有帮助,祝你好运!

修改:对于早期版本,例如1.6,您可以尝试以下内容,取自here

logger = sc._jvm.org.apache.log4j
logger.LogManager.getLogger("org"). setLevel(logger.Level.OFF)
# or
logger.LogManager.getRootLogger().setLevel(logger.Level.OFF)

我还没有测试过它,请告诉我它是否有效。