Skip to content

Commit

Permalink
SPARK-1190: Do not initialize log4j if slf4j log4j backend is not bei…
Browse files Browse the repository at this point in the history
…ng used

Author: Patrick Wendell <pwendell@gmail.com>

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

be21c11 [Patrick Wendell] Logging fix
(cherry picked from commit e59a3b6)

Signed-off-by: Patrick Wendell <pwendell@gmail.com>
  • Loading branch information
pwendell committed Mar 9, 2014
1 parent 0fc0fdb commit 0f0d044
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/src/main/scala/org/apache/spark/Logging.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 0f0d044

Please sign in to comment.