Class PerformanceLogFilter
- java.lang.Object
-
- com.devonfw.module.logging.common.impl.PerformanceLogFilter
-
- All Implemented Interfaces:
javax.servlet.Filter
public class PerformanceLogFilter extends Object implements javax.servlet.Filter
Request logging filter that measures the execution time of a request.- Since:
- 1.5.0
-
-
Constructor Summary
Constructors Constructor Description PerformanceLogFilter()The constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private StringcreateMessage(String... args)Returns aStringrepresenting the log message, which contains the given arguments separated by ';'voiddestroy()voiddoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)voidinit(javax.servlet.FilterConfig config)private voidlogPerformance(javax.servlet.ServletResponse response, long startTime, String url, Throwable error)Logs the request URL, execution time andHttpStatus.
-
-
-
Field Detail
-
LOG
private static final org.slf4j.Logger LOG
-
urlFilter
private String urlFilter
Optional filter to only measure execution time of requests that match the filter.
-
-
Method Detail
-
init
public void init(javax.servlet.FilterConfig config) throws javax.servlet.ServletException- Specified by:
initin interfacejavax.servlet.Filter- Throws:
javax.servlet.ServletException
-
doFilter
public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain) throws IOException, javax.servlet.ServletException- Specified by:
doFilterin interfacejavax.servlet.Filter- Throws:
IOExceptionjavax.servlet.ServletException
-
logPerformance
private void logPerformance(javax.servlet.ServletResponse response, long startTime, String url, Throwable error)Logs the request URL, execution time andHttpStatus. In case of an error also logs class name and error message.- Parameters:
response- - theServletResponsestartTime- - start time of thedoFilter(ServletRequest, ServletResponse, FilterChain)functionurl- - requested URLerror- - error thrown by the requested servlet,nullif execution did not cause an error
-
createMessage
private String createMessage(String... args)
Returns aStringrepresenting the log message, which contains the given arguments separated by ';'- Parameters:
args- - the arguments for the log message- Returns:
- a
Stringrepresenting the log message
-
destroy
public void destroy()
- Specified by:
destroyin interfacejavax.servlet.Filter
-
-