Class 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
    • 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.
    • Constructor Detail

      • PerformanceLogFilter

        public PerformanceLogFilter()
        The constructor.
    • Method Detail

      • init

        public void init​(javax.servlet.FilterConfig config)
                  throws javax.servlet.ServletException
        Specified by:
        init in interface javax.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:
        doFilter in interface javax.servlet.Filter
        Throws:
        IOException
        javax.servlet.ServletException
      • logPerformance

        private void logPerformance​(javax.servlet.ServletResponse response,
                                    long startTime,
                                    String url,
                                    Throwable error)
        Logs the request URL, execution time and HttpStatus. In case of an error also logs class name and error message.
        Parameters:
        response - - the ServletResponse
        startTime - - start time of the doFilter(ServletRequest, ServletResponse, FilterChain) function
        url - - requested URL
        error - - error thrown by the requested servlet, null if execution did not cause an error
      • createMessage

        private String createMessage​(String... args)
        Returns a String representing the log message, which contains the given arguments separated by ';'
        Parameters:
        args - - the arguments for the log message
        Returns:
        a String representing the log message
      • destroy

        public void destroy()
        Specified by:
        destroy in interface javax.servlet.Filter