gengliangwang commented on code in PR #46634:
URL: https://github.com/apache/spark/pull/46634#discussion_r1606286640
##########
common/utils/src/main/scala/org/apache/spark/internal/README.md:
##########
@@ -45,3 +45,52 @@ logger.error("Failed to abort the writer after failing to
write map output.", e)
## Exceptions
To ensure logs are compatible with Spark SQL and log analysis tools, avoid
`Exception.printStackTrace()`. Use `logError`, `logWarning`, and `logInfo`
methods from the `Logging` trait to log exceptions, maintaining structured and
parsable logs.
+
+## External third-party ecosystem access
+
+* If you want to output logs in `scala code` through the structured log
framework, you can define `custom LogKeys` as follows:
+
+```scala
+object CustomLogKeys {
+ // External third-party ecosystem `custom LogKey` must be `extends LogKey`
+ case object CUSTOM_LOG_KEY extends LogKey
+}
+```
+ and use it in `scala` code:
+
+```scala
+logInfo(log"${MDC(CustomLogKeys.CUSTOM_LOG_KEY, "key")}")
+```
+
+* If you want to output logs in `java code` through the structured log
framework, you can define `custom LogKeys` as follows:
+
+ when your project does **not depend on
`scala`**,
+```java
+class CustomLogKeys {
+ // External third-party ecosystem `custom LogKey` must be `implements LogKey`
+ public static class CUSTOM_LOG_KEY implements LogKey { }
+
+ // Singleton
+ public static final CUSTOM_LOG_KEY CUSTOM_LOG_KEY = new CUSTOM_LOG_KEY();
+}
+```
+ and use it in `java` code:
Review Comment:
why do we have   here?
--
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]