package com.yzk.servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.*;
public class TestLog4j extends HttpServlet {
Logger logger = null;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
response.setCharacterEncoding("GB18030");
logger.fatal("这是一条从 TestLog4j 产生的fatal信息!");
logger.error("这是一条从 TestLog4j 产生的error信息!");
logger.warn("这是一条从 TestLog4j 产生的warn信息!");
logger.debug("这是一条从 TestLog4j 产生的debug信息!");
logger.info("这是一条从 TestLog4j 产生的info信息!");
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
public void init() throws ServletException {
//PropertyConfigurator.configure(this.getServletContext().getRealPath("WEB-INF/log4j.properties"));
logger = Logger.getLogger(this.getClass());
}
}
|