Skip to content

Commit be21c11

Browse files
committed
Logging fix
1 parent 0b7b7fd commit be21c11

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)