Skip to content

Commit b6d40b7

Browse files
pwendellrxin
authored andcommitted
Merge pull request apache#560 from pwendell/logging. Closes apache#560.
[WIP] SPARK-1067: Default log4j initialization causes errors for those not using log4j To fix this - we add a check when initializing log4j. Author: Patrick Wendell <[email protected]> == Merge branch commits == commit ffdce513877f64b6eed6d36138c3e0003d392889 Author: Patrick Wendell <[email protected]> Date: Fri Feb 7 15:22:29 2014 -0800 Logging fix
1 parent f892da8 commit b6d40b7

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

core/src/main/scala/org/apache/spark/Logging.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package org.apache.spark
1919

2020
import org.apache.log4j.{LogManager, PropertyConfigurator}
2121
import org.slf4j.{Logger, LoggerFactory}
22+
import org.slf4j.impl.StaticLoggerBinder
2223

2324
/**
2425
* Utility trait for classes that want to log data. Creates a SLF4J logger for the class and allows
@@ -101,9 +102,11 @@ trait Logging {
101102
}
102103

103104
private def initializeLogging() {
104-
// If Log4j doesn't seem initialized, load a default properties file
105+
// If Log4j is being used, but is not initialized, load a default properties file
106+
val binder = StaticLoggerBinder.getSingleton
107+
val usingLog4j = binder.getLoggerFactoryClassStr.endsWith("Log4jLoggerFactory")
105108
val log4jInitialized = LogManager.getRootLogger.getAllAppenders.hasMoreElements
106-
if (!log4jInitialized) {
109+
if (!log4jInitialized && usingLog4j) {
107110
val defaultLogProps = "org/apache/spark/log4j-defaults.properties"
108111
val classLoader = this.getClass.getClassLoader
109112
Option(classLoader.getResource(defaultLogProps)) match {

0 commit comments

Comments
 (0)