ตัวอย่าง log4j init
public class Log4jInit extends HttpServlet {
private static Logger logger = Logger.getLogger(Log4jInit.class);
/**
*
*/
private static final long serialVersionUID = -6217487447859906018L;
private static final String CONTENT_TYPE = "text/html";
// Initialize global variables
@Override
public void init() throws ServletException {
File f = new File( getInitParameter("log4jPropsFile"));
if (!f.canRead()) {
throw new ServletException("Init log4j Exception");
}
logger.debug("Init log4j file = " + f.toString());
String log4jProp = f.toString();
PropertyConfigurator.configureAndWatch(log4jProp);
}
// Process the HTTP Get request
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Log4jInit</title></head>");
out.println("<body bgcolor=\"#ffffff\">");
out.println("<p>The servlet has received a GET. This is the reply.</p>");
out.println("</body>");
out.println("</html>");
out.close();
}
// Clean up resources
public void destroy() {
}
}
ตามตัวอย่างนี้เลยครับ
private static Logger logger = Logger.getLogger(Log4jInit.class);
/**
*
*/
private static final long serialVersionUID = -6217487447859906018L;
private static final String CONTENT_TYPE = "text/html";
// Initialize global variables
@Override
public void init() throws ServletException {
File f = new File( getInitParameter("log4jPropsFile"));
if (!f.canRead()) {
throw new ServletException("Init log4j Exception");
}
logger.debug("Init log4j file = " + f.toString());
String log4jProp = f.toString();
PropertyConfigurator.configureAndWatch(log4jProp);
}
// Process the HTTP Get request
@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Log4jInit</title></head>");
out.println("<body bgcolor=\"#ffffff\">");
out.println("<p>The servlet has received a GET. This is the reply.</p>");
out.println("</body>");
out.println("</html>");
out.close();
}
// Clean up resources
public void destroy() {
}
}
ตามตัวอย่างนี้เลยครับ
ความคิดเห็น
แสดงความคิดเห็น