Known Direct Subclasses
CommonsRequestLoggingFilter |
Simple request logging filter that writes the request URI
(and optionally the query string) to the Commons Log. |
Log4jNestedDiagnosticContextFilter |
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. |
ServletContextRequestLoggingFilter |
Simple request logging filter that writes the request URI
(and optionally the query string) to the ServletContext log. |
|
Class Overview
Base class for Filter
s that perform logging operations before and after a request is processed.
Subclasses should override the beforeRequest(HttpServletRequest, String)
and
afterRequest(HttpServletRequest, String)
methods to perform the actual logging around the request.
Subclasses are passed the message to write to the log in the beforeRequest
and
afterRequest
methods. By default, only the URI of the request is logged. However, setting the
includeQueryString
property to true
will cause the query string of the request to be
included also. The payload (body) of the request can be logged via the includePayload
flag. Note that
this will only log that which is read, which might not be the entire payload.
Prefixes and suffixes for the before and after messages can be configured using the
beforeMessagePrefix
, afterMessagePrefix
, beforeMessageSuffix
and
afterMessageSuffix
properties,
Summary
Public Methods |
void
|
setAfterMessagePrefix(String afterMessagePrefix)
Set the value that should be prepended to the log message written after a request is processed.
|
void
|
setAfterMessageSuffix(String afterMessageSuffix)
Set the value that should be appended to the log message written after a request is processed.
|
void
|
setBeforeMessagePrefix(String beforeMessagePrefix)
Set the value that should be prepended to the log message written before a request is processed.
|
void
|
setBeforeMessageSuffix(String beforeMessageSuffix)
Set the value that should be apppended to the log message written before a request is processed.
|
void
|
setIncludeClientInfo(boolean includeClientInfo)
Set whether or not the client address and session id should be included in the log message.
|
void
|
setIncludePayload(boolean includePayload)
Set whether or not the request payload (body) should be included in the log message.
|
void
|
setIncludeQueryString(boolean includeQueryString)
Set whether or not the query string should be included in the log message.
|
void
|
setMaxPayloadLength(int maxPayloadLength)
Sets the maximum length of the payload body to be included in the log message.
|
Protected Methods |
abstract
void
|
afterRequest(HttpServletRequest request, String message)
Concrete subclasses should implement this method to write a log message after the request is processed.
|
abstract
void
|
beforeRequest(HttpServletRequest request, String message)
Concrete subclasses should implement this method to write a log message before the request is processed.
|
String
|
createMessage(HttpServletRequest request, String prefix, String suffix)
Create a log message for the given request, prefix and suffix.
|
void
|
doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
Forwards the request to the next filter in the chain and delegates down to the subclasses to perform the actual
request logging both before and after the request is processed.
|
int
|
getMaxPayloadLength()
Return the maximum length of the payload body to be included in the log message.
|
boolean
|
isIncludeClientInfo()
Return whether or not the client address and session id should be included in the log message.
|
boolean
|
isIncludePayload()
Return whether or not the request payload (body) should be included in the log message.
|
boolean
|
isIncludeQueryString()
Return whether or not the query string should be included in the log message.
|
[Expand]
Inherited Methods |
From class
org.springframework.web.filter.OncePerRequestFilter
final
void
|
doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain)
This doFilter implementation stores a request attribute for
"already filtered", proceeding without filtering again if the
attribute is already there.
|
abstract
void
|
doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
Same contract as for doFilter , but guaranteed to be
just invoked once per request.
|
String
|
getAlreadyFilteredAttributeName()
Return the name of the request attribute that identifies that a request
is already filtered.
|
boolean
|
shouldNotFilter(HttpServletRequest request)
Can be overridden in subclasses for custom filtering control,
returning true to avoid filtering of the given request.
|
|
From class
org.springframework.web.filter.GenericFilterBean
final
void
|
addRequiredProperty(String property)
Subclasses can invoke this method to specify that this property
(which must match a JavaBean property they expose) is mandatory,
and must be supplied as a config parameter.
|
void
|
afterPropertiesSet()
Calls the initFilterBean() method that might
contain custom initialization of a subclass.
|
void
|
destroy()
Subclasses may override this to perform custom filter shutdown.
|
final
FilterConfig
|
getFilterConfig()
Make the FilterConfig of this filter available, if any.
|
final
String
|
getFilterName()
Make the name of this filter available to subclasses.
|
final
ServletContext
|
getServletContext()
Make the ServletContext of this filter available to subclasses.
|
final
void
|
init(FilterConfig filterConfig)
Standard way of initializing this filter.
|
void
|
initBeanWrapper(BeanWrapper bw)
Initialize the BeanWrapper for this GenericFilterBean,
possibly with custom editors.
|
void
|
initFilterBean()
Subclasses may override this to perform custom initialization.
|
final
void
|
setBeanName(String beanName)
Stores the bean name as defined in the Spring bean factory.
|
void
|
setEnvironment(Environment environment)
Set the Environment that this object runs in.
Any environment set here overrides the DefaultWebEnvironment
provided by default.
|
final
void
|
setServletContext(ServletContext servletContext)
Stores the ServletContext that the bean factory runs in.
|
|
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
|
From interface
javax.servlet.Filter
abstract
void
|
destroy()
|
abstract
void
|
doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2)
|
abstract
void
|
init(FilterConfig arg0)
|
|
From interface
org.springframework.beans.factory.BeanNameAware
abstract
void
|
setBeanName(String name)
Set the name of the bean in the bean factory that created this bean.
|
|
From interface
org.springframework.beans.factory.DisposableBean
abstract
void
|
destroy()
Invoked by a BeanFactory on destruction of a singleton.
|
|
From interface
org.springframework.beans.factory.InitializingBean
abstract
void
|
afterPropertiesSet()
Invoked by a BeanFactory after it has set all bean properties supplied
(and satisfied BeanFactoryAware and ApplicationContextAware).
|
|
From interface
org.springframework.context.EnvironmentAware
|
From interface
org.springframework.web.context.ServletContextAware
abstract
void
|
setServletContext(ServletContext servletContext)
Set the ServletContext that this object runs in.
|
|
Constants
public
static
final
String
DEFAULT_AFTER_MESSAGE_PREFIX
Constant Value:
"After request ["
public
static
final
String
DEFAULT_AFTER_MESSAGE_SUFFIX
public
static
final
String
DEFAULT_BEFORE_MESSAGE_PREFIX
Constant Value:
"Before request ["
public
static
final
String
DEFAULT_BEFORE_MESSAGE_SUFFIX
Public Constructors
public
AbstractRequestLoggingFilter
()
Public Methods
public
void
setAfterMessagePrefix
(String afterMessagePrefix)
Set the value that should be prepended to the log message written after a request is processed.
public
void
setAfterMessageSuffix
(String afterMessageSuffix)
Set the value that should be appended to the log message written after a request is processed.
public
void
setBeforeMessagePrefix
(String beforeMessagePrefix)
Set the value that should be prepended to the log message written before a request is processed.
public
void
setBeforeMessageSuffix
(String beforeMessageSuffix)
Set the value that should be apppended to the log message written before a request is processed.
public
void
setIncludeClientInfo
(boolean includeClientInfo)
Set whether or not 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
.
public
void
setIncludePayload
(boolean includePayload)
Set whether or not 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
.
public
void
setIncludeQueryString
(boolean includeQueryString)
Set whether or not 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
.
public
void
setMaxPayloadLength
(int maxPayloadLength)
Sets the maximum length of the payload body to be included in the log message. Default is 50 characters.
Protected Methods
protected
abstract
void
afterRequest
(HttpServletRequest request, 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
|
protected
abstract
void
beforeRequest
(HttpServletRequest request, 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
|
protected
String
createMessage
(HttpServletRequest request, String prefix, 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.
protected
void
doFilterInternal
(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
Forwards the request to the next filter in the chain and delegates down to the subclasses to perform the actual
request logging both before and after the request is processed.
protected
int
getMaxPayloadLength
()
Return the maximum length of the payload body to be included in the log message.
protected
boolean
isIncludeClientInfo
()
Return whether or not the client address and session id should be included in the log message.
protected
boolean
isIncludePayload
()
Return whether or not the request payload (body) should be included in the log message.
protected
boolean
isIncludeQueryString
()
Return whether or not the query string should be included in the log message.