Class Log4jServletFilter

  • All Implemented Interfaces:
    javax.servlet.Filter

    public class Log4jServletFilter
    extends java.lang.Object
    implements javax.servlet.Filter
    This is responsible for the following:
    • Clearing the logger context when the application has finished starting up.
    • Setting the logger context before processing a request and clearing it after processing a request.
    • Setting the logger context when the application is starting to shut down.
    This filter is a once-per-request filter. It is capable of filtering all the different types of requests (standard, asynchronous, error, etc.) but will not apply processing if the filter matches multiple times on the same logical request.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void destroy()  
      void doFilter​(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)  
      void init​(javax.servlet.FilterConfig filterConfig)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • LOGGER

        private static final Logger LOGGER
      • ALREADY_FILTERED_ATTRIBUTE

        static final java.lang.String ALREADY_FILTERED_ATTRIBUTE
      • servletContext

        private javax.servlet.ServletContext servletContext
    • Constructor Detail

      • Log4jServletFilter

        public Log4jServletFilter()
    • Method Detail

      • init

        public void init​(javax.servlet.FilterConfig filterConfig)
                  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 java.io.IOException,
                             javax.servlet.ServletException
        Specified by:
        doFilter in interface javax.servlet.Filter
        Throws:
        java.io.IOException
        javax.servlet.ServletException
      • destroy

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