简体   繁体   中英

How to set up logging level for Spark application in IntelliJ IDEA?

I'm working on a Scala project in IntelliJ that was created through SBT. The project has Spark as one of its dependencies. I'm still in the development phase so everything is running on my local machine.

How can I change Spark configurations like logging level, for example?

在 Eclipse 下设置 SparkContext 的日志级别对我有用

spark.sparkContext.setLogLevel("WARN")  

If you are working on the local development with IDE, you can change the log level at run-time by:

LogManager.getRootLogger.setLevel(Level.ALL)

Ps: Put that line after the SparkContext/ SQLContext was created in your code.

I would love to figure out how to do this with a project local properties file (an example file would be nice), but I was able to get this done in Spark 2.2 with the following code:

import org.apache.log4j.{Level, Logger}

object MySparkApp {

    def main(args: Array[String]): Unit = {
      Logger.getLogger("org.apache.spark").setLevel(Level.WARN)

将您的 log4j.properties 文件放在标记为资源的目录下,spark 将读取此 log4j 配置。

用于在 spark 2.0+ 中以编程方式关闭/设置日志级别

Logger.getLogger("org.apache.spark").setLevel(Level.OFF);

Spark by default logs almost everything you would like to see in the logs, however, if you need to change the logging behaviour, you can edit log4j.properties in the conf directory of your Apache Spark configuration. If you're using a prebuilt version, you can find it in /home/coco/Applications/spark-1.4.0-bin-hadoop2.6/conf directory. There is a template file "log4j.properties.template" that you have to copy to "log4j.properties" and edit it depending on your needs. I hope it helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM