【问题标题】:How to control Spark logging in IntelliJ如何在 IntelliJ 中控制 Spark 日志记录
【发布时间】:2020-04-01 21:27:46
【问题描述】:

我通常从 JUnit 运行东西,但我也尝试从 main 运行,这没有任何区别。


我已经阅读了近两打 SO 问题、博客文章和文章,并尝试了几乎所有方法来让 Spark 停止记录这么多。


我尝试过的事情:

  • log4j.properties 在资源文件夹中(在 srctest 中)
  • 使用spark-submit 添加失败的log4j.properties 并返回“error: missing application resources
  • Logger.getLogger("com").setLevel(Level.WARN);
  • Logger.getLogger("org").setLevel(Level.WARN);
  • Logger.getLogger("akka").setLevel(Level.WARN);
  • Logger.getRootLogger().setLevel(Level.WARN);
  • spark.sparkContext().setLogLevel("WARN");

  • 在另一个项目中,我让日志保持安静:

    Logger.getLogger("org").setLevel(Level.WARN);
    Logger.getLogger("akka").setLevel(Level.WARN);
    

    但它在这里不起作用。


    我如何创建我的 SparkSession:

    SparkSession spark = SparkSession
        .builder()
        .appName("RS-LDA")
        .master("local")
        .getOrCreate();
    


    如果您想查看我的更多代码,请告诉我。

    谢谢

    【问题讨论】:

    • 您是否尝试过更改log4j-defaults.properties 中Spark 的默认值?此默认属性文件通常位于您的 Spark 安装路径 (/etc/spark2/...)。

    标签: java apache-spark intellij-idea log4j


    【解决方案1】:

    我正在使用 IntelliJ 和 Spark,这对我有用:

    Logger.getRootLogger.setLevel(Level.ERROR)
    

    您也可以更改 Log Spark 配置。

    $ cd SPARK_HOME/conf
    $ gedit log4j.properties.template
    
    # find this lines in the file
    # Set everything to be logged to the console
    log4j.rootCategory=INFO, console
    
    and change to ERROR
    
    log4j.rootCategory=ERROR, console
    
    In this file you have other options tho change too
    
    # Set the default spark-shell log level to WARN. When running the spark-shell, the
    # log level for this class is used to overwrite the root logger's log level, so that
    # the user can have different defaults for the shell and regular Spark apps.
    log4j.logger.org.apache.spark.repl.Main=WARN
    
    # Settings to quiet third party logs that are too verbose
    .....
    
    And finally rename the log4j.properties.template file
     $ mv log4j.properties.template log4j.properties
    

    您可以点击此链接进行进一步配置:

    Logging in Spark with Log4j

    或者这个也是:

    Logging in Spark with Log4j. How to customize the driver and executors for YARN cluster mode.

    【讨论】:

      【解决方案2】:

      这可能是一个老问题,但我只是遇到了同样的问题。 为了解决这个问题,我所做的是:

      1. 添加private static Logger log = LoggerFactory.getLogger(Spark.class);
        作为类的字段。
      2. spark.sparkContext().setLogLevel("WARN"); 创建 Spark 会话后

      步骤 2 仅在步骤 1 之后有效。

      【讨论】:

        猜你喜欢
        • 2013-01-06
        • 2010-11-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-05-01
        • 2019-03-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多