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

LogFilter

public class LogFilter extends Object implements Filter

Fields Summary
private FilterConfig
config
private Logger
log
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.info(
            "Log id:" + id + ": Request received from: " + req.getRemoteHost() + " for " +
                req.getRequestURL()); }

        chain.doFilter(request,response);
    
public voidinit(javax.servlet.FilterConfig filterConfig)

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