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

Remko Popma commented on LOG4J2-1348:
-------------------------------------

I also like the static method better than the constructor since it hides the 
implementation and leaves open future improvements (like making the 
implementation garbage-free). 

Also, can we let the {{push}} and {{put}} methods return {{this}}? We can then 
replace the varargs on {{put}} with chained invocations like 

{code}
try (final CloseableThreadContext ctc = CloseableThreadContext
        .put("id", UUID.randomUUID().toString())
        .put("loginId", session.getAttribute("loginId"))) { 

   logger.debug("Message 1");
   logger.debug("Message 2");
}
{code}

> Add an AutoCloseable ThreadContext class: CloseableThreadContext
> ----------------------------------------------------------------
>
>                 Key: LOG4J2-1348
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-1348
>             Project: Log4j 2
>          Issue Type: Improvement
>          Components: API
>            Reporter: Greg Thomas
>            Assignee: Gary Gregory
>            Priority: Minor
>             Fix For: 2.6
>
>         Attachments: CloseableThreadContext.zip, thread-context.xml.patch
>
>
> The log4j2 API provides a ThreadContext - 
> https://logging.apache.org/log4j/2.x/manual/thread-context.html -  that 
> allows items to be added to a stack or a map for logging, and then 
> subsequently removed once they are no longer required.
> This sounds like an ideal candidate for a AutoCloseable implementation so 
> that items are removed automatically and no longer left around littering the 
> stack/map.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to