diff options
author | GuoQiang Li <witgo@qq.com> | 2014-08-01 23:55:11 -0700 |
---|---|---|
committer | Patrick Wendell <pwendell@gmail.com> | 2014-08-01 23:55:11 -0700 |
commit | adc8303294e26efb4ed15e5f5ba1062f7988625d (patch) | |
tree | 09d3231b718713f384e51711b31d737c5edcf6c7 /core | |
parent | 4bc3bb29a4b6ab24b6b7e1f8df26414c41c80ace (diff) | |
download | spark-adc8303294e26efb4ed15e5f5ba1062f7988625d.tar.gz spark-adc8303294e26efb4ed15e5f5ba1062f7988625d.tar.bz2 spark-adc8303294e26efb4ed15e5f5ba1062f7988625d.zip |
[SPARK-1470][SPARK-1842] Use the scala-logging wrapper instead of the directly sfl4j api
Author: GuoQiang Li <witgo@qq.com>
Closes #1369 from witgo/SPARK-1470_new and squashes the following commits:
66a1641 [GuoQiang Li] IncompatibleResultTypeProblem
73a89ba [GuoQiang Li] Use the scala-logging wrapper instead of the directly sfl4j api.
Diffstat (limited to 'core')
-rw-r--r-- | core/pom.xml | 4 | ||||
-rw-r--r-- | core/src/main/scala/org/apache/spark/Logging.scala | 39 | ||||
-rw-r--r-- | core/src/main/scala/org/apache/spark/util/SignalLogger.scala | 2 |
3 files changed, 29 insertions, 16 deletions
diff --git a/core/pom.xml b/core/pom.xml index 7c60cf10c3..47766ae5fb 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -99,6 +99,10 @@ <artifactId>jcl-over-slf4j</artifactId> </dependency> <dependency> + <groupId>com.typesafe.scala-logging</groupId> + <artifactId>scala-logging-slf4j_${scala.binary.version}</artifactId> + </dependency> + <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </dependency> diff --git a/core/src/main/scala/org/apache/spark/Logging.scala b/core/src/main/scala/org/apache/spark/Logging.scala index 807ef3e9c9..6e61c00b8d 100644 --- a/core/src/main/scala/org/apache/spark/Logging.scala +++ b/core/src/main/scala/org/apache/spark/Logging.scala @@ -18,8 +18,9 @@ package org.apache.spark import org.apache.log4j.{LogManager, PropertyConfigurator} -import org.slf4j.{Logger, LoggerFactory} +import org.slf4j.LoggerFactory import org.slf4j.impl.StaticLoggerBinder +import com.typesafe.scalalogging.slf4j.Logger import org.apache.spark.annotation.DeveloperApi import org.apache.spark.util.Utils @@ -39,61 +40,69 @@ trait Logging { // be serialized and used on another machine @transient private var log_ : Logger = null + // Method to get the logger name for this object + protected def logName = { + var className = this.getClass.getName + // Ignore trailing $'s in the class names for Scala objects + if (className.endsWith("$")) { + className = className.substring(0, className.length - 1) + } + className + } + // Method to get or create the logger for this object protected def log: Logger = { if (log_ == null) { initializeIfNecessary() - var className = this.getClass.getName - // Ignore trailing $'s in the class names for Scala objects - log_ = LoggerFactory.getLogger(className.stripSuffix("$")) + log_ = Logger(LoggerFactory.getLogger(logName)) } log_ } // Log methods that take only a String protected def logInfo(msg: => String) { - if (log.isInfoEnabled) log.info(msg) + log.info(msg) } protected def logDebug(msg: => String) { - if (log.isDebugEnabled) log.debug(msg) + log.debug(msg) } protected def logTrace(msg: => String) { - if (log.isTraceEnabled) log.trace(msg) + log.trace(msg) } protected def logWarning(msg: => String) { - if (log.isWarnEnabled) log.warn(msg) + log.warn(msg) } protected def logError(msg: => String) { - if (log.isErrorEnabled) log.error(msg) + log.error(msg) } // Log methods that take Throwables (Exceptions/Errors) too protected def logInfo(msg: => String, throwable: Throwable) { - if (log.isInfoEnabled) log.info(msg, throwable) + log.info(msg, throwable) } protected def logDebug(msg: => String, throwable: Throwable) { - if (log.isDebugEnabled) log.debug(msg, throwable) + log.debug(msg, throwable) } protected def logTrace(msg: => String, throwable: Throwable) { - if (log.isTraceEnabled) log.trace(msg, throwable) + log.trace(msg, throwable) } protected def logWarning(msg: => String, throwable: Throwable) { - if (log.isWarnEnabled) log.warn(msg, throwable) + log.warn(msg, throwable) } protected def logError(msg: => String, throwable: Throwable) { - if (log.isErrorEnabled) log.error(msg, throwable) + log.error(msg, throwable) } protected def isTraceEnabled(): Boolean = { - log.isTraceEnabled + log.underlying.isTraceEnabled } private def initializeIfNecessary() { diff --git a/core/src/main/scala/org/apache/spark/util/SignalLogger.scala b/core/src/main/scala/org/apache/spark/util/SignalLogger.scala index f77488ef3d..e84a6b951f 100644 --- a/core/src/main/scala/org/apache/spark/util/SignalLogger.scala +++ b/core/src/main/scala/org/apache/spark/util/SignalLogger.scala @@ -18,7 +18,7 @@ package org.apache.spark.util import org.apache.commons.lang3.SystemUtils -import org.slf4j.Logger +import com.typesafe.scalalogging.slf4j.Logger import sun.misc.{Signal, SignalHandler} /** |