1. Write an initialized servlet:
Package net.welovetennis.util.log;
Import javax.servlet. *; import javax.servlet.http. *; import org.apache.log4j. *;
/ ** *
Title: p> *
Description: p> *
Copyright: Copyright (c) 2004 p> *
Company: p> * @ Author not attributable * @version 1.0 * /
Public class log4jinit extends httpservlet {
// Initialize global variables public void init () throws ServletException {String prefix = getServletContext () getRealPath ( "/");. String file = getInitParameter ( "log4j"); // if the log4j-init-file is not set, Then no point in trying system.out.println ("................ log4j start"); if (file! = null) {PropertyConfigurator.configure (prefix file); }}} // process the http get request public void doget (httpservletRequest request, httpservletResponse response) {
} // clean up resources public void design () {}}
2. Modify the web. XML:
3. Depending on Web-INF Dressing file log4j.properties, and specify the output path: