类 AbstractRequestLoggingFilter
- java.lang.Object
- org.springframework.web.filter.GenericFilterBean
- org.springframework.web.filter.OncePerRequestFilter
- org.springframework.web.filter.AbstractRequestLoggingFilter
- 所有已实现的接口:
Filter
,Aware
,BeanNameAware
,DisposableBean
,InitializingBean
,EnvironmentAware
,EnvironmentCapable
,ServletContextAware
- 直接已知子类:
CommonsRequestLoggingFilter
,Log4jNestedDiagnosticContextFilter
,ServletContextRequestLoggingFilter
public abstract class AbstractRequestLoggingFilter extends OncePerRequestFilter
Base class forFilter
s that perform logging operations before and after a request is processed.Subclasses should override the
beforeRequest(HttpServletRequest, String)
andafterRequest(HttpServletRequest, String)
methods to perform the actual logging around the request.Subclasses are passed the message to write to the log in the
beforeRequest
andafterRequest
methods. By default, only the URI of the request is logged. However, setting theincludeQueryString
property totrue
will cause the query string of the request to be included also. The payload (body) of the request can be logged via theincludePayload
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
andafterMessageSuffix
properties.- 从以下版本开始:
- 1.2.5
- 作者:
- Rob Harrop, Juergen Hoeller, Rossen Stoyanchev
- 另请参阅:
beforeRequest(javax.servlet.http.HttpServletRequest, java.lang.String)
,afterRequest(javax.servlet.http.HttpServletRequest, java.lang.String)
字段概要
字段 修饰符和类型 字段 说明 static String
DEFAULT_AFTER_MESSAGE_PREFIX
static String
DEFAULT_AFTER_MESSAGE_SUFFIX
static String
DEFAULT_BEFORE_MESSAGE_PREFIX
static String
DEFAULT_BEFORE_MESSAGE_SUFFIX
从类继承的字段 org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIX
从类继承的字段 org.springframework.web.filter.GenericFilterBean
logger
构造器概要
构造器 构造器 说明 AbstractRequestLoggingFilter()
方法概要
所有方法 实例方法 抽象方法 具体方法 修饰符和类型 方法 说明 protected abstract void
afterRequest(HttpServletRequest request, String message)
Concrete subclasses should implement this method to write a log message after the request is processed.protected abstract void
beforeRequest(HttpServletRequest request, String message)
Concrete subclasses should implement this method to write a log message before the request is processed.protected String
createMessage(HttpServletRequest request, String prefix, String suffix)
Create a log message for the given request, 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 the client address and session id should be included in the log message.protected boolean
isIncludeHeaders()
Return whether the request headers should be included in the log message.protected boolean
isIncludePayload()
Return whether the request payload (body) should be included in the log message.protected boolean
isIncludeQueryString()
Return whether the query string should be included in the log message.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 appended to the log message written before a request is processed.void
setIncludeClientInfo(boolean includeClientInfo)
Set whether the client address and session id should be included in the log message.void
setIncludeHeaders(boolean includeHeaders)
Set whether the request headers should be included in the log message.void
setIncludePayload(boolean includePayload)
Set whether the request payload (body) should be included in the log message.void
setIncludeQueryString(boolean includeQueryString)
Set whether the query string should be included in the log message.void
setMaxPayloadLength(int maxPayloadLength)
Set the maximum length of the payload body to be included in the log message.protected boolean
shouldLog(HttpServletRequest request)
Determine whether to call thebeforeRequest(javax.servlet.http.HttpServletRequest, java.lang.String)
/afterRequest(javax.servlet.http.HttpServletRequest, java.lang.String)
methods for the current request, i.e. whether logging is currently active (and the log message is worth building).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.从类继承的方法 org.springframework.web.filter.OncePerRequestFilter
doFilter, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterErrorDispatch
从类继承的方法 org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
字段详细资料
DEFAULT_BEFORE_MESSAGE_PREFIX
public static final String DEFAULT_BEFORE_MESSAGE_PREFIX
- 另请参阅:
- 常量字段值
DEFAULT_BEFORE_MESSAGE_SUFFIX
public static final String DEFAULT_BEFORE_MESSAGE_SUFFIX
- 另请参阅:
- 常量字段值
DEFAULT_AFTER_MESSAGE_PREFIX
public static final String DEFAULT_AFTER_MESSAGE_PREFIX
- 另请参阅:
- 常量字段值
DEFAULT_AFTER_MESSAGE_SUFFIX
public static final String DEFAULT_AFTER_MESSAGE_SUFFIX
- 另请参阅:
- 常量字段值
构造器详细资料
AbstractRequestLoggingFilter
public AbstractRequestLoggingFilter()
方法详细资料
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 inweb.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 inweb.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 inweb.xml
.- 从以下版本开始:
- 4.3
isIncludeHeaders
protected boolean isIncludeHeaders()
Return whether the request headers should be included in the log message.- 从以下版本开始:
- 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 inweb.xml
.- 从以下版本开始:
- 3.0
isIncludePayload
protected boolean isIncludePayload()
Return whether the request payload (body) should be included in the log message.- 从以下版本开始:
- 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.- 从以下版本开始:
- 3.0
getMaxPayloadLength
protected int getMaxPayloadLength()
Return the maximum length of the payload body to be included in the log message.- 从以下版本开始:
- 3.0
setBeforeMessagePrefix
public void setBeforeMessagePrefix(String beforeMessagePrefix)
Set the value that should be prepended to the log message written before a request is processed.
setBeforeMessageSuffix
public void setBeforeMessageSuffix(String beforeMessageSuffix)
Set the value that should be appended to the log message written before a request is processed.
setAfterMessagePrefix
public void setAfterMessagePrefix(String afterMessagePrefix)
Set the value that should be prepended to the log message written after a request is processed.
setAfterMessageSuffix
public void setAfterMessageSuffix(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.
doFilterInternal
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException
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.
createMessage
protected String createMessage(HttpServletRequest request, String prefix, String suffix)
Create a log message for the given request, prefix and suffix.If
includeQueryString
istrue
, then the inner part of the log message will take the formrequest_uri?query_string
; otherwise the message will simply be of the formrequest_uri
.The final message is composed of the inner part as described and the supplied prefix and suffix.
shouldLog
protected boolean shouldLog(HttpServletRequest request)
Determine whether to call thebeforeRequest(javax.servlet.http.HttpServletRequest, java.lang.String)
/afterRequest(javax.servlet.http.HttpServletRequest, java.lang.String)
methods for the current request, i.e. whether logging is currently active (and the log message is worth building).The default implementation always returns
true
. Subclasses may override this with a log level check.- 参数:
request
- current HTTP request- 返回:
true
if the before/after method should get called;false
otherwise- 从以下版本开始:
- 4.1.5
beforeRequest
protected abstract void beforeRequest(HttpServletRequest request, String message)
Concrete subclasses should implement this method to write a log message before the request is processed.- 参数:
request
- current HTTP requestmessage
- the message to log
afterRequest
protected abstract void afterRequest(HttpServletRequest request, String message)
Concrete subclasses should implement this method to write a log message after the request is processed.- 参数:
request
- current HTTP requestmessage
- the message to log