java开源文档大全致力于打造中国最大最全的开源文档,它提供了最全面最权威的开源资料,同时为大家提供一个交流的平台,如果您有好的想法,欢迎您投稿.
1,写个初始化的SERVLET:
package net.welovetennis.util.log;
import javax.servlet.*; import javax.servlet.http.*; import org.apache.log4j.*;
/** *
Title: *
Description: *
Copyright: Copyright (c) 2004 *
Company: * @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 destroy() { } }
2,修改WEB。XML:
log4jinit net.welovetennis.util.log.Log4jInit log4j WEB-INF/log4j.properties 1
3,在WEB-INF下放配制文件log4j.properties,并指定输出路径:
log4j.rootLogger=INFO, A1 , R log4j.appender.A1=org.apache.log4j.ConsoleAppender log4j.appender.A1.layout=org.apache.log4j.PatternLayout log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%c]-[%p] %m%n log4j.appender.R=org.apache.log4j.RollingFileAppender log4j.appender.R.File=c:/project/david/racquet/logs/log4j.log log4j.appender.R.MaxFileSize=100KB log4j.appender.R.MaxBackupIndex=1 log4j.appender.R.layout=org.apache.log4j.PatternLayout log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n
致命英雄@2005-2-19 20:20:36
java开源文档研究struts,webwork,spring,tomcat,jboss,lucense,nutch,JUnit,eclipse......,如果您有什么意见,欢迎评论和留言. |