[ 
https://issues.apache.org/jira/browse/LOG4J2-2732?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16991738#comment-16991738
 ] 

Matt Pavlovich commented on LOG4J2-2732:
----------------------------------------

[~rgoers] you are welcome! Thank you for all your efforts. I'll make a note to 
add a unit test and PR for that.

[~ggregory] I understand the concern with the 
'code-will-execute-even-if-not-used' from my example. I think in general, the 
idea is when you have a several services interacting with a request none can be 
absolutely sure that the unique id is always specified ahead of time, so we 
find a lot of these lines where we check-if-exists then set the property. My 
example used a method, but that was for brevity, not indicative of how its 
always done. Many times it is a map.get() or string from a session type deal. 
Thanks.

> Add ThreadContext.putIfNull(String, String)
> -------------------------------------------
>
>                 Key: LOG4J2-2732
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-2732
>             Project: Log4j 2
>          Issue Type: New Feature
>          Components: API
>            Reporter: Matt Pavlovich
>            Priority: Major
>             Fix For: 2.13.0
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> Provide a helper method that provides a 1-liner to put an identifier only if 
> it is not currently set. This removes an if-check in all classes that share a 
> design approach of assessing a uniqueId, such as request id, etc.
> {noformat}
> if(!ThreadContext.containsKey("uniqueId")) {
>    ThreadContext.put("uniqueId", generateUniqueId());
> }
> {noformat}
> Proposed:
> {noformat}
> ThreadContext.putIfNull("uniqueId", generateUniqueId());
> {noformat}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to