0 Replies Latest reply on Apr 14, 2006 3:31 PM by Chris Cheshire

    log4j & servlet filters

    Chris Cheshire Newbie

      I have followed the wiki regarding Repository Selectors for initialising log4j, and have got it working for my web apps.

      I am using struts 1.2 and in the struts actions, I can use log4j and have it log properly. I also have a log statement inside the InitServlet where log4j is initialised and it works too.

      However when I try and log from inside a servlet filter the logging does not get executed at all.

      The filter is one to determine if a user is logged in, and if not redirect to the login page. This is working as the redirection happens properly. However the logging is not.

      This works:

      public class InitServlet
      extends HttpServlet {
       private static Logger log;
       public void init(ServletConfig config)
       throws ServletException {
       ServletContext context = config.getServletContext();
       System.setProperty("log4j.log.dir", getInitParameter("log4j.log_directory"));
       String configFile = getInitParameter("log4j.config_file");
       Log4JRepositorySelector.init(config, configFile);
       log = Logger.getLogger(getClass());
       log.debug("logging initialised");

      This doesn't work:
      public class LoginFilter
      implements Filter {
       private Logger log = Logger.getLogger(getClass());
       public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
       throws IOException, ServletException {
       HttpServletRequest req = (HttpServletRequest)request;
       log.debug("uri = " + req.getRequestURI());
       // otherwise continue
       chain.doFilter(request, response);

      Can someone shed some light on this please?