org.springframework.web.filter

Class AbstractRequestLoggingFilter

    • Field Detail

      • DEFAULT_BEFORE_MESSAGE_PREFIX

        public static final java.lang.String DEFAULT_BEFORE_MESSAGE_PREFIX
        The default value prepended to the log message written before a request is processed.
        See Also:
        Constant Field Values
      • DEFAULT_BEFORE_MESSAGE_SUFFIX

        public static final java.lang.String DEFAULT_BEFORE_MESSAGE_SUFFIX
        The default value appended to the log message written before a request is processed.
        See Also:
        Constant Field Values
      • DEFAULT_AFTER_MESSAGE_PREFIX

        public static final java.lang.String DEFAULT_AFTER_MESSAGE_PREFIX
        The default value prepended to the log message written after a request is processed.
        See Also:
        Constant Field Values
      • DEFAULT_AFTER_MESSAGE_SUFFIX

        public static final java.lang.String DEFAULT_AFTER_MESSAGE_SUFFIX
        The default value appended to the log message written after a request is processed.
        See Also:
        Constant Field Values
    • Constructor Detail

      • AbstractRequestLoggingFilter

        public AbstractRequestLoggingFilter()
    • Method Detail

      • setIncludeQueryString

        public void setIncludeQueryString(boolean includeQueryString)
        Set whether the query string should be included in the log message.

        Should be configured using an <init-param> for parameter name "includeQueryString" in the filter definition in web.xml.

      • isIncludeQueryString

        protected boolean isIncludeQueryString()
        Return whether the query string should be included in the log message.
      • setIncludeClientInfo

        public void setIncludeClientInfo(boolean includeClientInfo)
        Set whether the client address and session id should be included in the log message.

        Should be configured using an <init-param> for parameter name "includeClientInfo" in the filter definition in web.xml.

      • isIncludeClientInfo

        protected boolean isIncludeClientInfo()
        Return whether the client address and session id should be included in the log message.
      • setIncludeHeaders

        public void setIncludeHeaders(boolean includeHeaders)
        Set whether the request headers should be included in the log message.

        Should be configured using an <init-param> for parameter name "includeHeaders" in the filter definition in web.xml.

        Since:
        4.3
      • isIncludeHeaders

        protected boolean isIncludeHeaders()
        Return whether the request headers should be included in the log message.
        Since:
        4.3
      • setIncludePayload

        public void setIncludePayload(boolean includePayload)
        Set whether the request payload (body) should be included in the log message.

        Should be configured using an <init-param> for parameter name "includePayload" in the filter definition in web.xml.

        Since:
        3.0
      • isIncludePayload

        protected boolean isIncludePayload()
        Return whether the request payload (body) should be included in the log message.
        Since:
        3.0
      • setMaxPayloadLength

        public void setMaxPayloadLength(int maxPayloadLength)
        Set the maximum length of the payload body to be included in the log message. Default is 50 characters.
        Since:
        3.0
      • getMaxPayloadLength

        protected int getMaxPayloadLength()
        Return the maximum length of the payload body to be included in the log message.
        Since:
        3.0
      • setBeforeMessagePrefix

        public void setBeforeMessagePrefix(java.lang.String beforeMessagePrefix)
        Set the value that should be prepended to the log message written before a request is processed.
      • setBeforeMessageSuffix

        public void setBeforeMessageSuffix(java.lang.String beforeMessageSuffix)
        Set the value that should be appended to the log message written before a request is processed.
      • setAfterMessagePrefix

        public void setAfterMessagePrefix(java.lang.String afterMessagePrefix)
        Set the value that should be prepended to the log message written after a request is processed.
      • setAfterMessageSuffix

        public void setAfterMessageSuffix(java.lang.String afterMessageSuffix)
        Set the value that should be appended to the log message written after a request is processed.
      • shouldNotFilterAsyncDispatch

        protected boolean shouldNotFilterAsyncDispatch()
        The default value is "false" so that the filter may log a "before" message at the start of request processing and an "after" message at the end from when the last asynchronously dispatched thread is exiting.
        Overrides:
        shouldNotFilterAsyncDispatch in class OncePerRequestFilter
      • createMessage

        protected java.lang.String createMessage(HttpServletRequest request,
                                                 java.lang.String prefix,
                                                 java.lang.String suffix)
        Create a log message for the given request, prefix and suffix.

        If includeQueryString is true, then the inner part of the log message will take the form request_uri?query_string; otherwise the message will simply be of the form request_uri.

        The final message is composed of the inner part as described and the supplied prefix and suffix.

      • beforeRequest

        protected abstract void beforeRequest(HttpServletRequest request,
                                              java.lang.String message)
        Concrete subclasses should implement this method to write a log message before the request is processed.
        Parameters:
        request - current HTTP request
        message - the message to log
      • afterRequest

        protected abstract void afterRequest(HttpServletRequest request,
                                             java.lang.String message)
        Concrete subclasses should implement this method to write a log message after the request is processed.
        Parameters:
        request - current HTTP request
        message - the message to log