anchovYu commented on code in PR #47732:
URL: https://github.com/apache/spark/pull/47732#discussion_r1715717254
##########
common/utils/src/test/scala/org/apache/spark/util/StructuredLoggingSuite.scala:
##########
@@ -438,6 +438,44 @@ class StructuredLoggingSuite extends LoggingSuiteBase {
assert((log"\r" + log"\n" + log"\t" + log"\b").message == "\r\n\t\b")
assert((log"\r${MDC(LogKeys.EXECUTOR_ID, 1)}\n".message == "\r1\n"))
}
+
+ test("disabled structured logging won't log context") {
+ Logging.disableStructuredLogging()
+ val expectedPatternWithoutContext = compactAndToRegexPattern(
+ s"""
+ {
+ "ts": "<timestamp>",
+ "level": "INFO",
+ "msg": "Lost executor 1.",
+ "logger": "$className"
+ }""")
+
+ Seq(
+ () => logInfo(log"Lost executor ${MDC(LogKeys.EXECUTOR_ID, "1")}."),
+ () => logInfo( // blocked when explicitly constructing the
MessageWithContext
+ MessageWithContext(
+ "Lost executor 1.",
+ new java.util.HashMap[String, String] {
put(LogKeys.EXECUTOR_ID.name, "1") }
+ )
+ )
+ ).foreach { f =>
+ val logOutput = captureLogOutput(f)
+ assert(expectedPatternWithoutContext.r.matches(logOutput))
+ }
+ Logging.enableStructuredLogging()
+ }
+
+ test("setting to MDC gets logged") {
+ val mdcPattern = s""""${LogKeys.DATA.name}":"some-data""""
+
+ org.slf4j.MDC.put(LogKeys.DATA.name, "some-data")
Review Comment:
@gengliangwang this tests the function like
[setMDCForTask](https://github.com/apache/spark/blob/f08165003cff6843541b1a8330c63673812af10d/core/src/main/scala/org/apache/spark/executor/Executor.scala#L931)
gets logged
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]