12

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?

Jacek Laskowski
  • 72,696
  • 27
  • 242
  • 420
Nabegh
  • 3,249
  • 6
  • 25
  • 26

6 Answers6

14

Setting the log level on the SparkContext worked for me under Eclipse

spark.sparkContext.setLogLevel("WARN")  
rschmidt13
  • 349
  • 3
  • 3
  • This worked for me. The accepted answer of setting the log level for all the loggers didn't work. Although, one problem with this is that, I'm not seeing any logs, not even the ones from my application. Don't know if it's because of this or something else. – Durga Swaroop Jun 25 '18 at 12:15
9

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.

ngtrkhoa
  • 754
  • 5
  • 6
2

Put your log4j.properties file under a directory marked as resources, spark will read this log4j configuration.

tianhaopx
  • 53
  • 4
2

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)
1

For shutting down/setting log level programmatically in spark 2.0+

Logger.getLogger("org.apache.spark").setLevel(Level.OFF);
Kobynet
  • 983
  • 11
  • 23
0

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.

MPAK
  • 39
  • 2
  • 5