org.springframework.web.filter
Class Log4jNestedDiagnosticContextFilter

java.lang.Object
  extended by org.springframework.web.filter.GenericFilterBean
      extended by org.springframework.web.filter.OncePerRequestFilter
          extended by org.springframework.web.filter.AbstractRequestLoggingFilter
              extended by org.springframework.web.filter.Log4jNestedDiagnosticContextFilter
All Implemented Interfaces:
Filter, Aware, BeanNameAware, DisposableBean, InitializingBean, EnvironmentAware, ServletContextAware

public class Log4jNestedDiagnosticContextFilter
extends AbstractRequestLoggingFilter

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

Since:
1.2.5
Author:
Juergen Hoeller, Rob Harrop
See Also:
AbstractRequestLoggingFilter.setIncludeQueryString(boolean), AbstractRequestLoggingFilter.setBeforeMessagePrefix(java.lang.String), AbstractRequestLoggingFilter.setBeforeMessageSuffix(java.lang.String), AbstractRequestLoggingFilter.setAfterMessagePrefix(java.lang.String), AbstractRequestLoggingFilter.setAfterMessageSuffix(java.lang.String), NDC.push(String), NDC.pop()

Field Summary
protected  Logger log4jLogger
          Logger available to subclasses
 
Fields inherited from class org.springframework.web.filter.AbstractRequestLoggingFilter
DEFAULT_AFTER_MESSAGE_PREFIX, DEFAULT_AFTER_MESSAGE_SUFFIX, DEFAULT_BEFORE_MESSAGE_PREFIX, DEFAULT_BEFORE_MESSAGE_SUFFIX
 
Fields inherited from class org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIX
 
Fields inherited from class org.springframework.web.filter.GenericFilterBean
logger
 
Constructor Summary
Log4jNestedDiagnosticContextFilter()
           
 
Method Summary
protected  void afterRequest(HttpServletRequest request, String message)
          Removes the log message from the Log4J NDC after the request is processed and logs the after-request message through Log4J.
protected  void beforeRequest(HttpServletRequest request, String message)
          Logs the before-request message through Log4J and adds a message the Log4J NDC before the request is processed.
protected  String getNestedDiagnosticContextMessage(HttpServletRequest request)
          Determine the message to be pushed onto the Log4J nested diagnostic context.
 
Methods inherited from class org.springframework.web.filter.AbstractRequestLoggingFilter
createMessage, doFilterInternal, getMaxPayloadLength, isIncludeClientInfo, isIncludePayload, isIncludeQueryString, setAfterMessagePrefix, setAfterMessageSuffix, setBeforeMessagePrefix, setBeforeMessageSuffix, setIncludeClientInfo, setIncludePayload, setIncludeQueryString, setMaxPayloadLength
 
Methods inherited from class org.springframework.web.filter.OncePerRequestFilter
doFilter, getAlreadyFilteredAttributeName, shouldNotFilter
 
Methods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, destroy, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log4jLogger

protected final Logger log4jLogger
Logger available to subclasses

Constructor Detail

Log4jNestedDiagnosticContextFilter

public Log4jNestedDiagnosticContextFilter()
Method Detail

beforeRequest

protected void beforeRequest(HttpServletRequest request,
                             String message)
Logs the before-request message through Log4J and adds a message the Log4J NDC before the request is processed.

Specified by:
beforeRequest in class AbstractRequestLoggingFilter
Parameters:
request - current HTTP request
message - the message to log

getNestedDiagnosticContextMessage

protected String getNestedDiagnosticContextMessage(HttpServletRequest request)
Determine the message to be pushed onto the Log4J nested diagnostic context.

Default is a plain request log message without prefix or suffix.

Parameters:
request - current HTTP request
Returns:
the message to be pushed onto the Log4J NDC
See Also:
AbstractRequestLoggingFilter.createMessage(javax.servlet.http.HttpServletRequest, java.lang.String, java.lang.String)

afterRequest

protected void afterRequest(HttpServletRequest request,
                            String message)
Removes the log message from the Log4J NDC after the request is processed and logs the after-request message through Log4J.

Specified by:
afterRequest in class AbstractRequestLoggingFilter
Parameters:
request - current HTTP request
message - the message to log