public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain)
            throws IOException, ServletException {
        
        if (debug) {
            log("LoginFilter:doFilter()");
        }
        String contextPath =  filterConfig.getServletContext().getRealPath("/WEB-INF/login_attempts.log");
        File loginLog = new File(contextPath);
        FileWriter fw = new FileWriter(loginLog, true);
        String timeStamp = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").format(Calendar.getInstance().getTime());
        String logStr = timeStamp + " " + request.getRemoteAddr() + " " + request.getParameter("username") + "\n";
        fw.append(logStr);
        fw.close();
        Throwable problem = null;
        try {
            chain.doFilter(request, response);
        } catch (Throwable t) {
	    // If an exception is thrown somewhere down the filter chain,
            // we still want to execute our after processing, and then
            // rethrow the problem after that.
            problem = t;
            t.printStackTrace();
        }
	// If there was a problem, we want to rethrow it if it is
        // a known type, otherwise log it.
        if (problem != null) {
            if (problem instanceof ServletException) {
                throw (ServletException) problem;
            }
            if (problem instanceof IOException) {
                throw (IOException) problem;
            }
            sendProcessingError(problem, response);
        }
    }