FileDocCategorySizeDatePackage
ContextLogger.javaAPI DocExample1246Mon Sep 08 11:00:14 BST 2003com.jspservletcookbook

ContextLogger

public class ContextLogger extends Object implements ServletContextListener

Fields Summary
private Logger
log
Constructors Summary
public ContextLogger()

Methods Summary
public voidcontextDestroyed(javax.servlet.ServletContextEvent sce)

  
  String name = sce.getServletContext().getServletContextName();
    
    //log request of the INFO level
    log.info("ServletContext shut down: " + (name == null ? "" : name ));
      
    
public voidcontextInitialized(javax.servlet.ServletContextEvent sce)


  ServletContext context = sce.getServletContext();
  
 String realPath = context.getRealPath("/");
 String fileSep = System.getProperty("file.separator" );
  
  if (realPath != null && (! realPath.endsWith(fileSep)))
      realPath = realPath + fileSep;
   //Initialize logger here:
  PropertyConfigurator.configure(realPath + "WEB-INF/classes/" + context.getInitParameter("logger-config"));
  log = Logger.getLogger(ContextLogger.class);

 String name = context.getServletContextName();
    //log request about servlet context being initialized
    log.info("ServletContext ready: " + (name == null ? "" : name ));