//Log4j from Apache is required
import org.apache.log4j.Logger;
import javax.servlet.*;
import javax.servlet.http.*;
public class LoggerNewConfig extends HttpServlet {
private Logger log = null;
public void init() {
log = Logger.getLogger(LoggerNewConfig.class);
log.info("LoggerNewConfig started.");
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
//display a DEBUG level message
log.debug("Sending a DEBUG message");
// display an INFO level message
log.info("Sending an INFO message");
//better display some HTML
response.setContentType("text/html");
java.io.PrintWriter out = response.getWriter();
out.println("Servlet logging");
out.println
("Hello from a Logger with its own configuration in the log4j.properties file
");
out.println("Your logger name is: " + log.getName() + "
");
out.println("Your logger parent is: " + log.getParent().getName()
+ "
");
out.println("");
out.close();
} //end doGet
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
doGet(request, response);
}
}