public class UsageLog
extends java.lang.Object
Uses the SLF4J MDC framework (see @link{org.slf4j.MDC} for more details).
If properly configured, each log entry within the context thread will include the gathered context information. For instance, in log4j and slf4j, the appender pattern would contain strings with the form "%X{<contextKey>}", where "<contextKey>" is a context key value. The context key strings are given in each setup method below.
MDC| Constructor and Description |
|---|
UsageLog() |
| Modifier and Type | Method and Description |
|---|---|
void |
add2map(java.lang.String key,
java.lang.String value) |
static java.lang.String |
closingMessageForRequestContext(int resCode,
long resSizeInBytes)
Return a log message appropriate for logging at the completion of
the contexts HTTP request.
|
static java.lang.String |
closingMessageNonRequestContext()
Return a log message appropriate for logging at the close of
the non-request context.
|
static java.lang.String |
setupNonRequestContext()
Gather context information for the current non-request thread and
return a log message appropriate for logging.
|
static java.lang.String |
setupRequestContext(javax.servlet.http.HttpServletRequest req)
Gather context information for the given HTTP request and return
a log message appropriate for logging at the start of the request.
|
public static java.lang.String setupRequestContext(javax.servlet.http.HttpServletRequest req)
The following context information is gathered:
Call this method at the start of each HttpServlet doXXX() method (e.g., doGet(), doPut()) or Spring MVC Controller handle() method.
req - the current requestpublic static java.lang.String closingMessageForRequestContext(int resCode,
long resSizeInBytes)
Call this method at every exit point in each HttpServlet doXXX() method (e.g., doGet(), doPut()) or Spring MVC Controller handle() method.
resCode - - the result code for this request.resSizeInBytes - - the number of bytes returned in this result, -1 if unknown.public static java.lang.String setupNonRequestContext()
The following context information is gathered:
Call this method only for non-request servlet activities, e.g., during init() or destroy().
public static java.lang.String closingMessageNonRequestContext()
public void add2map(java.lang.String key,
java.lang.String value)