Log4jNestedDiagnosticContextFilter (Spring Framework 3.2.1.RELEASE API)
Date: 2013-01-24

org.springframework.web.filter

## Class Log4jNestedDiagnosticContextFilter

- java.lang.Object
- - org.springframework.web.filter.GenericFilterBean
  - - org.springframework.web.filter.OncePerRequestFilter
    - - org.springframework.web.filter.AbstractRequestLoggingFilter
      - - 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

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `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

    Constructors
    Constructor and Description
    `Log4jNestedDiagnosticContextFilter()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `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, shouldNotFilterAsyncDispatch`

    - ### Methods inherited from class org.springframework.web.filter.OncePerRequestFilter

      `doFilter, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterErrorDispatch`

    - ### 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