LogFilter.javaAPI DocExample1587Tue Jun 10 11:42:44 BST 2003com.jspservletcookbook


public class LogFilter extends Object implements Filter

Fields Summary
private FilterConfig
private Logger
Constructors Summary
public LogFilter()
Creates new RequestFilter

Methods Summary
public voiddestroy()

        /*called before the Filter instance is removed 
        from service by the web container*/
        log = null;
public voiddoFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response, javax.servlet.FilterChain chain)

    HttpServletRequest req = null;
    String id = config.getInitParameter("log-id");
    if (id == null)
        id = "unknown";
    if (log != null && (request instanceof HttpServletRequest)){
        req = (HttpServletRequest) request;
            "Log id:" + id + ": Request received from: " + req.getRemoteHost() + " for " +
                req.getRequestURL()); }

public voidinit(javax.servlet.FilterConfig filterConfig)

        this.config = filterConfig;
        //load the configuration for this application's loggers using the file
  PropertyConfigurator.configure(config.getServletContext().getRealPath("/") +
        log = Logger.getLogger(LogFilter.class);"Logger instantiated in "+ getClass().getName());