1.将log4j 的jar 置于 lib 下
2.log4j.properties置于 classes 下
3.log4j.properties
log4j.rootCategory=ERROR, file,console
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.PatternLayout
#log4j.appender.console.layout.ConversionPattern= %t %p - %m %n
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=./example.log // D:\Program Files\netbeans-5.0\enterprise2\jakarta-tomcat-5.5.9\bin
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern= %d{yyyy-MM-dd HH:mm:ss} : %t %p - %m %n
4. import=org.apache.commons.logging.Log;
% 3B import=org.apache.commons.logging.LogFactory;
5.Log logger = LogFactory.getLog(this.getClass());
logger.error("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
阅读(949) | 评论(0) | 转发(0) |