anchovYu opened a new pull request, #47732:
URL: https://github.com/apache/spark/pull/47732

   ### What changes were proposed in this pull request?
   <!--
   Please clarify what changes you are proposing. The purpose of this section 
is to outline the changes and how this PR fixes the issue. 
   If possible, please consider writing useful notes for better and faster 
reviews in your PR. See the examples below.
     1. If you refactor some codes with changing classes, showing the class 
hierarchy will help reviewers.
     2. If you fix some SQL features, you can provide some references of other 
DBMSes.
     3. If there is design documentation, please add the link.
     4. If there is a discussion in the mailing list, please add the link.
   -->
   To use structured logging developers usually do
   ```scala
   logInfo(log"Lost executor ${MDC(LogKeys.EXECUTOR_ID, "1")}."),
   ```
   When the structured logging conf is off, the context is not logged.
   However if explicitly constructing the LogEntry and calling the public API,
   ```scala
   logInfo(
     MessageWithContext(
       "Lost executor 1.",
       new java.util.HashMap[String, String] { put(LogKeys.EXECUTOR_ID.name, 
"1") }
     )
   )
   ```
   the conf does not take effect and even when it is off, the context is still 
logged.
   
   
   This PR creates a fix for both cases to observe the conf, by toggling in the 
`withLogContext` function.
   
   This PR also adds a extra small test on explicitly setting MDC.
   
   ### Why are the changes needed?
   To keep consistency between APIs.
   
   
   ### Does this PR introduce _any_ user-facing change?
   No.
   
   
   ### How was this patch tested?
   Added new unit tests.
   
   
   ### Was this patch authored or co-authored using generative AI tooling?
   <!--
   If generative AI tooling has been used in the process of authoring this 
patch, please include the
   phrase: 'Generated-by: ' followed by the name of the tool and its version.
   If no, write 'No'.
   Please refer to the [ASF Generative Tooling 
Guidance](https://www.apache.org/legal/generative-tooling.html) for details.
   -->
   


-- 
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]

Reply via email to