I'd like to stop various messages that are coming on spark shell.
I tried to edit the log4j.properties
file in order to stop these message.
Here are the contents of log4j.properties
# Define the root logger with appender file
log4j.rootCategory=WARN, console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.target=System.err
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{yy/MM/dd HH:mm:ss} %p %c{1}: %m%n
# Settings to quiet third party logs that are too verbose
log4j.logger.org.eclipse.jetty=WARN
log4j.logger.org.eclipse.jetty.util.component.AbstractLifeCycle=ERROR
log4j.logger.org.apache.spark.repl.SparkIMain$exprTyper=INFO
log4j.logger.org.apache.spark.repl.SparkILoop$SparkILoopInterpreter=INFO
But messages are still getting displayed on the console.
Here are some example messages
15/01/05 15:11:45 INFO SparkEnv: Registering BlockManagerMaster
15/01/05 15:11:45 INFO DiskBlockManager: Created local directory at /tmp/spark-local-20150105151145-b1ba
15/01/05 15:11:45 INFO MemoryStore: MemoryStore started with capacity 0.0 B.
15/01/05 15:11:45 INFO ConnectionManager: Bound socket to port 44728 with id = ConnectionManagerId(192.168.100.85,44728)
15/01/05 15:11:45 INFO BlockManagerMaster: Trying to register BlockManager
15/01/05 15:11:45 INFO BlockManagerMasterActor$BlockManagerInfo: Registering block manager 192.168.100.85:44728 with 0.0 B RAM
15/01/05 15:11:45 INFO BlockManagerMaster: Registered BlockManager
15/01/05 15:11:45 INFO HttpServer: Starting HTTP Server
15/01/05 15:11:45 INFO HttpBroadcast: Broadcast server star
How do I stop these?
In addition to all the above posts, here is what solved the issue for me.
Spark uses slf4j to bind to loggers. If log4j is not the first binding found, you can edit log4j.properties files all you want, the loggers are not even used. For example, this could be a possible SLF4J output:
So here the SimpleLoggerFactory was used, which does not care about log4j settings.
Excluding the slf4j-simple package from my project via
resolved the issue, as now the log4j logger binding is used and any setting in log4j.properties is adhered to. F.Y.I. my log4j properties file contains (besides the normal configuration)
Hope this helps!
tl;dr
Details-
Internally,
setLogLevel
callsorg.apache.log4j.Level.toLevel(logLevel)
that it then uses to set usingorg.apache.log4j.LogManager.getRootLogger().setLevel(level)
.You can set up the default logging for Spark shell in
conf/log4j.properties
. Useconf/log4j.properties.template
as a starting point.Setting Log Levels in Spark Applications
In standalone Spark applications or while in Spark Shell session, use the following:
Disabling logging(in log4j):
Use the following in
conf/log4j.properties
to disable logging completely:Reference: Mastering Spark by Jacek Laskowski.
Simply add below param to your spark-shell OR spark-submit command
Check exact property name (log4jspark.root.logger here) from log4j.properties file. Hope this helps, cheers!
Thanks @AkhlD and @Sachin Janani for suggesting changes in
.conf
file.Following code solved my issue:
1) Added
import org.apache.log4j.{Level, Logger}
in import section2) Added following line after creation of spark context object i.e. after
val sc = new SparkContext(conf)
: