Package de.bund.bva.isyfact.logging.http
Class HttpHeaderNestedDiagnosticContextFilter
java.lang.Object
org.springframework.web.filter.GenericFilterBean
org.springframework.web.filter.OncePerRequestFilter
org.springframework.web.filter.AbstractRequestLoggingFilter
de.bund.bva.isyfact.logging.http.HttpHeaderNestedDiagnosticContextFilter
- All Implemented Interfaces:
javax.servlet.Filter,org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.context.EnvironmentAware,org.springframework.core.env.EnvironmentCapable,org.springframework.web.context.ServletContextAware
public class HttpHeaderNestedDiagnosticContextFilter
extends org.springframework.web.filter.AbstractRequestLoggingFilter
A servlet filter which reads the Correlation-ID from the http header
correlationIdHttpHeaderName
and makes it accessible to the logging framework.
If the header is not set, a new Correlation-ID is generated.
Processing the Correlation-ID in a servlet filter ensures that it is set as early as possible within the request. Therefore all of spring's log messages contain the correct Correlation-ID.
The Configuration is done automatically by MdcFilterAutoConfiguration.
-
Field Summary
Fields inherited from class org.springframework.web.filter.AbstractRequestLoggingFilter
DEFAULT_AFTER_MESSAGE_PREFIX, DEFAULT_AFTER_MESSAGE_SUFFIX, DEFAULT_BEFORE_MESSAGE_PREFIX, DEFAULT_BEFORE_MESSAGE_SUFFIXFields inherited from class org.springframework.web.filter.OncePerRequestFilter
ALREADY_FILTERED_SUFFIXFields inherited from class org.springframework.web.filter.GenericFilterBean
logger -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidafterRequest(javax.servlet.http.HttpServletRequest request, String message) Removes the log message from the Slf4j MDC after the request is processed and logs the after-request message through SLF4J.protected voidbeforeRequest(javax.servlet.http.HttpServletRequest request, String message) Logs the before-request message through Slf4j and adds a message the Slf4j MDC before the request is processed.protected StringgetNestedDiagnosticContextMessage(javax.servlet.http.HttpServletRequest request) Determine the message to be pushed onto the SLF4J nested diagnostic context.voidsetCorrelationIdHttpHeaderName(String correlationIdHttpHeaderName) Sets the name of the http header with the Correlation-ID.Methods inherited from class org.springframework.web.filter.AbstractRequestLoggingFilter
createMessage, doFilterInternal, getHeaderPredicate, getMaxPayloadLength, getMessagePayload, isIncludeClientInfo, isIncludeHeaders, isIncludePayload, isIncludeQueryString, setAfterMessagePrefix, setAfterMessageSuffix, setBeforeMessagePrefix, setBeforeMessageSuffix, setHeaderPredicate, setIncludeClientInfo, setIncludeHeaders, setIncludePayload, setIncludeQueryString, setMaxPayloadLength, shouldLog, shouldNotFilterAsyncDispatchMethods inherited from class org.springframework.web.filter.OncePerRequestFilter
doFilter, doFilterNestedErrorDispatch, getAlreadyFilteredAttributeName, isAsyncDispatch, isAsyncStarted, shouldNotFilter, shouldNotFilterErrorDispatchMethods inherited from class org.springframework.web.filter.GenericFilterBean
addRequiredProperty, afterPropertiesSet, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
-
Constructor Details
-
HttpHeaderNestedDiagnosticContextFilter
public HttpHeaderNestedDiagnosticContextFilter()
-
-
Method Details
-
setCorrelationIdHttpHeaderName
Sets the name of the http header with the Correlation-ID.- Parameters:
correlationIdHttpHeaderName- the name of the http header with the Correlation-ID.
-
getNestedDiagnosticContextMessage
Determine the message to be pushed onto the SLF4J 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 Slf4j MDC
- See Also:
-
AbstractRequestLoggingFilter.createMessage(javax.servlet.http.HttpServletRequest, java.lang.String, java.lang.String)
-
beforeRequest
Logs the before-request message through Slf4j and adds a message the Slf4j MDC before the request is processed.- Specified by:
beforeRequestin classorg.springframework.web.filter.AbstractRequestLoggingFilter
-
afterRequest
Removes the log message from the Slf4j MDC after the request is processed and logs the after-request message through SLF4J.- Specified by:
afterRequestin classorg.springframework.web.filter.AbstractRequestLoggingFilter
-