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: [email protected]
For additional commands, e-mail: [email protected]