beliefer commented on code in PR #45729:
URL: https://github.com/apache/spark/pull/45729#discussion_r1540500697


##########
common/utils/src/main/scala/org/apache/spark/internal/Logging.scala:
##########
@@ -55,6 +91,43 @@ trait Logging {
     log_
   }
 
+  implicit class LogStringContext(val sc: StringContext) {
+    def log(args: Any*): MessageWithContext = {
+      val processedParts = sc.parts.iterator
+      val sb = new StringBuilder(processedParts.next())
+      lazy val map = new java.util.HashMap[String, String]()
+
+      args.foreach { arg =>
+        arg match {
+          case mdc: MDC =>
+            sb.append(mdc.value)
+            if (Logging.isStructuredLoggingEnabled) {
+              map.put(mdc.key.toString.toLowerCase(Locale.ROOT), mdc.value)
+            }
+          case other =>
+            // Note: all the arguments are supposed to be MDCs, but we only 
throw an exception
+            //       if we are running in test mode. This is to avoid breaking 
existing code.

Review Comment:
   Shall we change `args: Any*` to `args: MDC* ? So we can avoid the match path.



##########
common/utils/src/main/scala/org/apache/spark/internal/Logging.scala:
##########
@@ -55,6 +91,43 @@ trait Logging {
     log_
   }
 
+  implicit class LogStringContext(val sc: StringContext) {
+    def log(args: Any*): MessageWithContext = {
+      val processedParts = sc.parts.iterator
+      val sb = new StringBuilder(processedParts.next())
+      lazy val map = new java.util.HashMap[String, String]()
+
+      args.foreach { arg =>
+        arg match {
+          case mdc: MDC =>
+            sb.append(mdc.value)
+            if (Logging.isStructuredLoggingEnabled) {
+              map.put(mdc.key.toString.toLowerCase(Locale.ROOT), mdc.value)
+            }
+          case other =>
+            // Note: all the arguments are supposed to be MDCs, but we only 
throw an exception
+            //       if we are running in test mode. This is to avoid breaking 
existing code.

Review Comment:
   Shall we change `args: Any*` to `args: MDC*` ? So we can avoid the match 
path.



##########
common/utils/src/main/scala/org/apache/spark/internal/Logging.scala:
##########
@@ -55,6 +91,43 @@ trait Logging {
     log_
   }
 
+  implicit class LogStringContext(val sc: StringContext) {
+    def log(args: Any*): MessageWithContext = {
+      val processedParts = sc.parts.iterator
+      val sb = new StringBuilder(processedParts.next())
+      lazy val map = new java.util.HashMap[String, String]()
+
+      args.foreach { arg =>
+        arg match {
+          case mdc: MDC =>
+            sb.append(mdc.value)
+            if (Logging.isStructuredLoggingEnabled) {
+              map.put(mdc.key.toString.toLowerCase(Locale.ROOT), mdc.value)
+            }
+          case other =>
+            // Note: all the arguments are supposed to be MDCs, but we only 
throw an exception
+            //       if we are running in test mode. This is to avoid breaking 
existing code.

Review Comment:
   Shall we change `args: Any*` to `args: MDC* ? So we can avoid the match path.



-- 
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: reviews-unsubscr...@spark.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to