Skip to content

Commit 044971e

Browse files
infynyxxzsxwing
authored andcommitted
[SPARK-16131] initialize internal logger lazily in Scala preferred way
## What changes were proposed in this pull request? Initialize logger instance lazily in Scala preferred way ## How was this patch tested? By running `./build/mvn clean test` locally Author: Prajwal Tuladhar <praj@infynyxx.com> Closes #13842 from infynyxx/spark_internal_logger.
1 parent 857ecff commit 044971e

File tree

2 files changed

+4
-12
lines changed

2 files changed

+4
-12
lines changed

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,17 @@ private[spark] trait Logging {
3232

3333
// Make the log field transient so that objects with Logging can
3434
// be serialized and used on another machine
35-
@transient private var log_ : Logger = null
35+
@transient lazy val log: Logger = {
36+
initializeLogIfNecessary(false)
37+
LoggerFactory.getLogger(logName)
38+
}
3639

3740
// Method to get the logger name for this object
3841
protected def logName = {
3942
// Ignore trailing $'s in the class names for Scala objects
4043
this.getClass.getName.stripSuffix("$")
4144
}
4245

43-
// Method to get or create the logger for this object
44-
protected def log: Logger = {
45-
if (log_ == null) {
46-
initializeLogIfNecessary(false)
47-
log_ = LoggerFactory.getLogger(logName)
48-
}
49-
log_
50-
}
51-
5246
// Log methods that take only a String
5347
protected def logInfo(msg: => String) {
5448
if (log.isInfoEnabled) log.info(msg)

core/src/main/scala/org/apache/spark/scheduler/cluster/CoarseGrainedSchedulerBackend.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ class CoarseGrainedSchedulerBackend(scheduler: TaskSchedulerImpl, val rpcEnv: Rp
100100
// instance across threads
101101
private val ser = SparkEnv.get.closureSerializer.newInstance()
102102

103-
override protected def log = CoarseGrainedSchedulerBackend.this.log
104-
105103
protected val addressToExecutorId = new HashMap[RpcAddress, String]
106104

107105
private val reviveThread =

0 commit comments

Comments
 (0)