diff options
author | Patrick Wendell <pwendell@gmail.com> | 2014-03-08 16:02:42 -0800 |
---|---|---|
committer | Patrick Wendell <pwendell@gmail.com> | 2014-03-08 16:02:42 -0800 |
commit | e59a3b6c415b95e8137f5a154716b12653a8aed0 (patch) | |
tree | 11dd343593fa5482614de455bd863fa505f618e9 /core | |
parent | c2834ec081df392ca501a75b5af06efaa5448509 (diff) | |
download | spark-e59a3b6c415b95e8137f5a154716b12653a8aed0.tar.gz spark-e59a3b6c415b95e8137f5a154716b12653a8aed0.tar.bz2 spark-e59a3b6c415b95e8137f5a154716b12653a8aed0.zip |
SPARK-1190: Do not initialize log4j if slf4j log4j backend is not being used
Author: Patrick Wendell <pwendell@gmail.com>
Closes #107 from pwendell/logging and squashes the following commits:
be21c11 [Patrick Wendell] Logging fix
Diffstat (limited to 'core')
-rw-r--r-- | core/src/main/scala/org/apache/spark/Logging.scala | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/core/src/main/scala/org/apache/spark/Logging.scala b/core/src/main/scala/org/apache/spark/Logging.scala index b749e5414d..7423082e34 100644 --- a/core/src/main/scala/org/apache/spark/Logging.scala +++ b/core/src/main/scala/org/apache/spark/Logging.scala @@ -19,6 +19,7 @@ package org.apache.spark import org.apache.log4j.{LogManager, PropertyConfigurator} import org.slf4j.{Logger, LoggerFactory} +import org.slf4j.impl.StaticLoggerBinder /** * Utility trait for classes that want to log data. Creates a SLF4J logger for the class and allows @@ -101,9 +102,11 @@ trait Logging { } private def initializeLogging() { - // If Log4j doesn't seem initialized, load a default properties file + // If Log4j is being used, but is not initialized, load a default properties file + val binder = StaticLoggerBinder.getSingleton + val usingLog4j = binder.getLoggerFactoryClassStr.endsWith("Log4jLoggerFactory") val log4jInitialized = LogManager.getRootLogger.getAllAppenders.hasMoreElements - if (!log4jInitialized) { + if (!log4jInitialized && usingLog4j) { val defaultLogProps = "org/apache/spark/log4j-defaults.properties" val classLoader = this.getClass.getClassLoader Option(classLoader.getResource(defaultLogProps)) match { |