public interface LogContext
pop()
is called. These class is specifically designed for multithreaded environments and
allow to separate otherwise intermixed log messages.
Here is an example of a hypothetical servlet. On every request, service method stores remote address on log context; every log message will include remote address no matter if called directly from servlet service or from a nested method.
private static final LogContext logContext = LogFactory.getLogContext(); protected void service(HttpServletRequest httpRequest, HttpServletResponse httpResponse) { // store request remote address to current thread logContext.push(httpRequest.getRemoteHost()); try { // log message can be configured to include request remote address log.debug(...); } finally { // takes care to cleanup request remote address from current thread since thread can be reused logContext.pop(); } }
Modifier and Type | Method and Description |
---|---|
void |
pop()
Cleanup diagnostic data from logger context.
|
void |
push(String diagnosticContext)
Push diagnostic context data on logger related to current thread.
|
void push(String diagnosticContext)
pop()
is called on current thread.diagnosticContext
- diagnostic context data.void pop()
push(String)
with this pop; if this
method is not called pushed diagnostic data remains on thread till thread terminates.Copyright © 2018. All rights reserved.