windows下配置log4j

windows下配置log4j

1,在classes(即src)目录下建立log4j.properties
2,在log4j.properties中添加
log4j.rootCategory=INFO, A1
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.file=../webapps/zebra_erp/WEB-INF/logs/zebra_
log4j.appender.A1.DatePattern=yyyy-MM-dd'.log'
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%d %-5p - %m%n
3,添加一个InitLog4j的servlet,并使其load-on-startup为1,在init()中添加
String prefix = this.getServletContext().getRealPath("/");
String path = prefix+"WEB-INF\\classes\\log4j.properties";
PropertyConfigurator.configure(path);
4,代码中使用
private static Logger logger = Logger.getLogger(DBUtil.class);

 



你可能感兴趣的:(windows下配置log4j)