logging-log4j-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Greg Thomas <greg.d.tho...@gmail.com>
Subject Re: ThreadContext - auto-closable?
Date Fri, 01 Apr 2016 16:03:08 GMT
Thanks; https://issues.apache.org/jira/browse/LOG4J2-1348 raised, any
additional thoughts welcome!

Greg

On 1 April 2016 at 14:50, Ralph Goers <ralph.goers@dslextreme.com> wrote:
> 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
>

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