public class PerformanceLogFilter extends Object implements javax.servlet.Filter
| Modifier and Type | Field and Description |
|---|---|
private static org.slf4j.Logger |
LOG |
private String |
urlFilter
Optional filter to only measure execution time of requests that match the filter.
|
| Constructor and Description |
|---|
PerformanceLogFilter()
The constructor.
|
| Modifier and Type | Method and Description |
|---|---|
private String |
createMessage(String... args)
Returns a
String representing the log message, which contains the given arguments separated by ';' |
void |
destroy() |
void |
doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain) |
void |
init(javax.servlet.FilterConfig config) |
private void |
logPerformance(javax.servlet.ServletResponse response,
long startTime,
String url,
Throwable error)
Logs the request URL, execution time and
HttpStatus. |
private static final org.slf4j.Logger LOG
private String urlFilter
public void init(javax.servlet.FilterConfig config)
throws javax.servlet.ServletException
init in interface javax.servlet.Filterjavax.servlet.ServletExceptionpublic void doFilter(javax.servlet.ServletRequest request,
javax.servlet.ServletResponse response,
javax.servlet.FilterChain chain)
throws IOException,
javax.servlet.ServletException
doFilter in interface javax.servlet.FilterIOExceptionjavax.servlet.ServletExceptionprivate void logPerformance(javax.servlet.ServletResponse response,
long startTime,
String url,
Throwable error)
HttpStatus. In case of an error also logs class name and error
message.response - - the ServletResponsestartTime - - start time of the doFilter(ServletRequest, ServletResponse, FilterChain) functionurl - - requested URLerror - - error thrown by the requested servlet, null if execution did not cause an errorprivate String createMessage(String... args)
String representing the log message, which contains the given arguments separated by ';'args - - the arguments for the log messageString representing the log messagepublic void destroy()
destroy in interface javax.servlet.FilterCopyright © 2014–2019 devon4j-Team. All rights reserved.