public class

Log4jNestedDiagnosticContextInterceptor

extends Object
implements WebRequestInterceptor
java.lang.Object
   ↳ org.springframework.web.context.request.Log4jNestedDiagnosticContextInterceptor

Class Overview

Request logging interceptor that adds a request context message to the Log4J nested diagnostic context (NDC) before the request is processed, removing it again after the request is processed.

See Also
  • org.apache.log4j.NDC#push(String)
  • org.apache.log4j.NDC#pop()

Summary

Fields
protected final Logger log4jLogger Logger available to subclasses
Public Constructors
Log4jNestedDiagnosticContextInterceptor()
Public Methods
void afterCompletion(WebRequest request, Exception ex)
Removes the log message from the Log4J NDC after the request is processed.
void postHandle(WebRequest request, ModelMap model)
Intercept the execution of a request handler after its successful invocation, right before view rendering (if any).
void preHandle(WebRequest request)
Adds a message the Log4J NDC before the request is processed.
void setIncludeClientInfo(boolean includeClientInfo)
Set whether or not the session id and user name should be included in the log message.
Protected Methods
String getNestedDiagnosticContextMessage(WebRequest request)
Determine the message to be pushed onto the Log4J nested diagnostic context.
boolean isIncludeClientInfo()
Return whether or not the session id and user name should be included in the log message.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.web.context.request.WebRequestInterceptor

Fields

protected final Logger log4jLogger

Logger available to subclasses

Public Constructors

public Log4jNestedDiagnosticContextInterceptor ()

Public Methods

public void afterCompletion (WebRequest request, Exception ex)

Removes the log message from the Log4J NDC after the request is processed.

Parameters
request the current web request
ex exception thrown on handler execution, if any
Throws
Exception

public void postHandle (WebRequest request, ModelMap model)

Intercept the execution of a request handler after its successful invocation, right before view rendering (if any).

Allows for modifying context resources after successful handler execution (for example, flushing a Hibernate Session).

Parameters
request the current web request
model the map of model objects that will be exposed to the view (may be null). Can be used to analyze the exposed model and/or to add further model attributes, if desired.
Throws
Exception

public void preHandle (WebRequest request)

Adds a message the Log4J NDC before the request is processed.

Parameters
request the current web request
Throws
Exception

public void setIncludeClientInfo (boolean includeClientInfo)

Set whether or not the session id and user name should be included in the log message.

Protected Methods

protected String getNestedDiagnosticContextMessage (WebRequest request)

Determine the message to be pushed onto the Log4J nested diagnostic context.

Default is the request object's getDescription result.

Parameters
request current HTTP request
Returns
  • the message to be pushed onto the Log4J NDC

protected boolean isIncludeClientInfo ()

Return whether or not the session id and user name should be included in the log message.