logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ralph Goers <ralph.go...@dslextreme.com>
Subject Re: ThreadContext - auto-closable?
Date Fri, 01 Apr 2016 13:50:59 GMT
This would be a perfect case to go ahead and create it and either attach it as a patch to a
Jira issue or reference it in a pull request from a Jira issue.

Ralph

> On Apr 1, 2016, at 3:16 AM, Greg Thomas <greg.d.thomas@gmail.com> wrote:
> 
> I was looking at the ThreadContext section of the API @
> http://logging.apache.org/log4j/2.x/manual/thread-context.html -
> particularly the Thread Context Map
> 
> Given it's important to remember to clear the map at the "end" of
> processing, would this be a good case for an auto-closeable, so you
> could do something like (based on the documented example) ...
> 
> try (final CloseableThreadContext ctc = new
> CloseableThreadContext("id", UUID.randomUUID().toString(),
> "ipAddress", request.getRemoteAddr())) {
> 
>    logger.debug("Message 1");
>    ...
>    logger.debug("Message 2");
>    ...
> }
> 
> i.e. creating the object adds the key/value pairs to the Thread
> Context Map, and when the object is auto-closed they are automatically
> removed from the Thread Context Map (or returned to their original
> value).
> 
> Have I missed anything?
> 
> (and as I finished writing this, it strikes me that I don't need any
> changes to the API, I can do this independently, but it may be worth
> adding).
> 
> Greg
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
> For additional commands, e-mail: log4j-user-help@logging.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-user-unsubscribe@logging.apache.org
For additional commands, e-mail: log4j-user-help@logging.apache.org


Mime
View raw message