LoggerSkel for Servlet : Log « Servlets « Java






LoggerSkel for Servlet

 
//Log4j from Apache is required


import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import javax.servlet.*;
import javax.servlet.http.*;

public class LoggerSkel extends HttpServlet {

  private Logger log;

  public void init() {

    PropertyConfigurator.configure(getServletContext().getRealPath("/")
        + "WEB-INF/classes/servletLog.properties");
    log = Logger.getLogger(LoggerSkel.class);
    log.debug("Instance created of: " + getClass().getName());

  }

  public void doGet(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, java.io.IOException {

    //do logging here if necessary

  } //end doGet

}

           
         
  








Related examples in the same category

1.Servlets Logging Filter Demo
2.Logging Filter
3.Context log
4.Logger without configure file
5.Logger Servlet
6.Another logger servlet
7.Logger new config
8.Servlet: Root logger
9.Session logger
10.Context logger
11.Log Filter
12.Log in ServletContext
13.Servlet Logging