本文共 1001 字,大约阅读时间需要 3 分钟。
第一步,去下载log4j的包
第二步,在web.xml中添加
- <context-param>
- <param-name>log4jConfigLocation</param-name>
- <param-value>classpath:log4j.properties</param-value>
- </context-param>
第三步,在jsp中添加
- <%@ page import="org.apache.log4j.Logger"%>
- <% Logger log = Logger.getLogger("myapplogger"); StringBuffer sb = new StringBuffer(); log.info(sb.append("start").append(" - ").append(" - ").append(this.getClass())); %>
第四步,在log4j.properties中添加
- log4j.logger.myapplogger=info,interfacelog
- log4j.additivity.myapplogger=false
- log4j.appender.interfacelog=org.apache.log4j.RollingFileAppender
- log4j.appender.interfacelog.File=interface.log
- log4j.appender.interfacelog.MaxFileSize=2048KB
- # Keep three backup files.
- log4j.appender.interfacelog.MaxBackupIndex=3000
- # Pattern to output: date priority [category] - message
- log4j.appender.interfacelog.layout=org.apache.log4j.PatternLayout
- log4j.appender.interfacelog.layout.ConversionPattern=%d %p [%c] - %m%n
这样就可以了
本文转自sucre03 51CTO博客,原文链接:http://blog.51cto.com/sucre/1001793,如需转载请自行联系原作者