You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by pw...@apache.org on 2014/03/09 01:02:53 UTC

git commit: SPARK-1190: Do not initialize log4j if slf4j log4j backend is not being used

Repository: spark
Updated Branches:
  refs/heads/master c2834ec08 -> e59a3b6c4


SPARK-1190: Do not initialize log4j if slf4j log4j backend is not being used

Author: Patrick Wendell <pw...@gmail.com>

Closes #107 from pwendell/logging and squashes the following commits:

be21c11 [Patrick Wendell] Logging fix


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/e59a3b6c
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/e59a3b6c
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/e59a3b6c

Branch: refs/heads/master
Commit: e59a3b6c415b95e8137f5a154716b12653a8aed0
Parents: c2834ec
Author: Patrick Wendell <pw...@gmail.com>
Authored: Sat Mar 8 16:02:42 2014 -0800
Committer: Patrick Wendell <pw...@gmail.com>
Committed: Sat Mar 8 16:02:42 2014 -0800

----------------------------------------------------------------------
 core/src/main/scala/org/apache/spark/Logging.scala | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/e59a3b6c/core/src/main/scala/org/apache/spark/Logging.scala
----------------------------------------------------------------------
diff --git a/core/src/main/scala/org/apache/spark/Logging.scala b/core/src/main/scala/org/apache/spark/Logging.scala
index b749e54..7423082 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 {