1818package org .apache .spark
1919
2020import org .apache .log4j .{LogManager , PropertyConfigurator }
21- import org .slf4j .{ Logger , LoggerFactory }
21+ import org .slf4j .LoggerFactory
2222import org .slf4j .impl .StaticLoggerBinder
23+ import com .typesafe .scalalogging .slf4j .Logger
2324
2425import org .apache .spark .annotation .DeveloperApi
2526import org .apache .spark .util .Utils
@@ -39,61 +40,69 @@ trait Logging {
3940 // be serialized and used on another machine
4041 @ transient private var log_ : Logger = null
4142
43+ // Method to get the logger name for this object
44+ protected def logName = {
45+ var className = this .getClass.getName
46+ // Ignore trailing $'s in the class names for Scala objects
47+ if (className.endsWith(" $" )) {
48+ className = className.substring(0 , className.length - 1 )
49+ }
50+ className
51+ }
52+
4253 // Method to get or create the logger for this object
4354 protected def log : Logger = {
4455 if (log_ == null ) {
4556 initializeIfNecessary()
46- var className = this .getClass.getName
47- // Ignore trailing $'s in the class names for Scala objects
48- log_ = LoggerFactory .getLogger(className.stripSuffix(" $" ))
57+ log_ = Logger (LoggerFactory .getLogger(logName))
4958 }
5059 log_
5160 }
5261
5362 // Log methods that take only a String
5463 protected def logInfo (msg : => String ) {
55- if (log.isInfoEnabled) log.info(msg)
64+ log.info(msg)
5665 }
5766
5867 protected def logDebug (msg : => String ) {
59- if (log.isDebugEnabled) log.debug(msg)
68+ log.debug(msg)
6069 }
6170
6271 protected def logTrace (msg : => String ) {
63- if (log.isTraceEnabled) log.trace(msg)
72+ log.trace(msg)
6473 }
6574
6675 protected def logWarning (msg : => String ) {
67- if (log.isWarnEnabled) log.warn(msg)
76+ log.warn(msg)
6877 }
6978
7079 protected def logError (msg : => String ) {
71- if (log.isErrorEnabled) log.error(msg)
80+ log.error(msg)
7281 }
7382
7483 // Log methods that take Throwables (Exceptions/Errors) too
7584 protected def logInfo (msg : => String , throwable : Throwable ) {
76- if (log.isInfoEnabled) log.info(msg, throwable)
85+ log.info(msg, throwable)
7786 }
7887
7988 protected def logDebug (msg : => String , throwable : Throwable ) {
80- if (log.isDebugEnabled) log.debug(msg, throwable)
89+ log.debug(msg, throwable)
8190 }
8291
8392 protected def logTrace (msg : => String , throwable : Throwable ) {
84- if (log.isTraceEnabled) log.trace(msg, throwable)
93+ log.trace(msg, throwable)
8594 }
8695
8796 protected def logWarning (msg : => String , throwable : Throwable ) {
88- if (log.isWarnEnabled) log.warn(msg, throwable)
97+ log.warn(msg, throwable)
8998 }
9099
91100 protected def logError (msg : => String , throwable : Throwable ) {
92- if (log.isErrorEnabled) log.error(msg, throwable)
101+ log.error(msg, throwable)
93102 }
94103
95104 protected def isTraceEnabled (): Boolean = {
96- log.isTraceEnabled
105+ log.underlying. isTraceEnabled
97106 }
98107
99108 private def initializeIfNecessary () {
0 commit comments