Skip to content

Commit a26a7a2

Browse files
vinooganeshbulldozer-bot[bot]
authored andcommitted
In SafeLogging, make the log transient (apache-spark-on-k8s#471)
### Upstream SPARK-XXXXX ticket and PR link (if not applicable, explain) No upstream PR - SafeLogging is palantir specific. ### What changes were proposed in this pull request? If the log in SafeLogging is not marked as transient, it is included in the serialized version of TorrentBroadcast, which causes issues. This excludes the log from being included in the TorrentBroadcast object, by making the log transient. ### How was this patch tested? No testing for this - the logic is taken from upstream
1 parent 3b1a092 commit a26a7a2

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

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

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,51 +18,66 @@
1818
package org.apache.spark.internal
1919

2020
import com.palantir.logsafe.Arg
21-
import org.slf4j.LoggerFactory
21+
import org.slf4j.{Logger, LoggerFactory}
2222

2323
trait SafeLogging {
24-
private[this] val log_ = LoggerFactory.getLogger(this.getClass.getName)
24+
// Taken from Logging.scala
25+
@transient private[this] var safeLog_ : Logger = null
2526

26-
def safeLogIsInfoEnabled: Boolean = log_.isInfoEnabled
27+
// Method to get the logger name for this object
28+
protected def getLogName: String = {
29+
// Ignore trailing $'s in the class names for Scala objects
30+
this.getClass.getName.stripSuffix("$")
31+
}
32+
33+
// Method to get or create the logger for this object
34+
protected def safeLog: Logger = {
35+
if (safeLog_ == null) {
36+
safeLog_ = LoggerFactory.getLogger(getLogName)
37+
}
38+
safeLog_
39+
}
40+
41+
def safeLogIsInfoEnabled: Boolean = safeLog.isInfoEnabled
2742

2843
def safeLogInfo(message: String, args: Arg[_]*): Unit = {
29-
if (log_.isInfoEnabled) log_.info(message, args: _*)
44+
if (safeLog.isInfoEnabled) safeLog.info(message, args: _*)
3045
}
3146

3247
def safeLogInfo(message: String, error: Throwable, args: Arg[_]*): Unit = {
33-
if (log_.isInfoEnabled) log_.info(message, args :+ error: _*)
48+
if (safeLog.isInfoEnabled) safeLog.info(message, args :+ error: _*)
3449
}
3550

3651
def safeLogDebug(message: String, args: Arg[_]*): Unit = {
37-
if (log_.isDebugEnabled) log_.debug(message, args: _*)
52+
if (safeLog.isDebugEnabled) safeLog.debug(message, args: _*)
3853
}
3954

4055
def safeLogDebug(message: String, error: Throwable, args: Arg[_]*): Unit = {
41-
if (log_.isDebugEnabled) log_.debug(message, args :+ error: _*)
56+
if (safeLog.isDebugEnabled) safeLog.debug(message, args :+ error: _*)
4257
}
4358

4459
def safeLogTrace(message: String, args: Arg[_]*): Unit = {
45-
if (log_.isTraceEnabled) log_.trace(message, args: _*)
60+
if (safeLog.isTraceEnabled) safeLog.trace(message, args: _*)
4661
}
4762

4863
def safeLogTrace(message: String, error: Throwable, args: Arg[_]*): Unit = {
49-
if (log_.isTraceEnabled) log_.trace(message, args :+ error: _*)
64+
if (safeLog.isTraceEnabled) safeLog.trace(message, args :+ error: _*)
5065
}
5166

5267
def safeLogWarning(message: String, args: Arg[_]*): Unit = {
53-
if (log_.isWarnEnabled) log_.warn(message, args: _*)
68+
if (safeLog.isWarnEnabled) safeLog.warn(message, args: _*)
5469
}
5570

5671
def safeLogWarning(message: String, error: Throwable, args: Arg[_]*): Unit = {
57-
if (log_.isWarnEnabled) log_.warn(message, args :+ error: _*)
72+
if (safeLog.isWarnEnabled) safeLog.warn(message, args :+ error: _*)
5873
}
5974

6075
def safeLogError(message: String, args: Arg[_]*): Unit = {
61-
if (log_.isErrorEnabled) log_.error(message, args: _*)
76+
if (safeLog.isErrorEnabled) safeLog.error(message, args: _*)
6277
}
6378

6479
def safeLogError(message: String, error: Throwable, args: Arg[_]*): Unit = {
65-
if (log_.isErrorEnabled) log_.error(message, args :+ error: _*)
80+
if (safeLog.isErrorEnabled) safeLog.error(message, args :+ error: _*)
6681
}
6782
}
6883

0 commit comments

Comments
 (0)