在spring中集成log4j
1 下载相关jar
下载commons-logging-1.1.1.jar和log4j-1.2.14.jar
2 创建log4j.properties,放在classes目录下
log4j.rootLogger=info,file,console
#log4j.logger.console=info
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.layout=org.apache.log4j.SimpleLayout
#log4j.logger.file=info
log4j.appender.file=org.apache.log4j.RollingFileAppender
log4j.appender.file.File=E:/wdpk/work/cms/log/log.txt
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%t %p - %m%n
3 配制web.xml
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>/WEB-INF/classes/config/log4j.properties</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
4在程序中使用
Log log = LogFactory.getLog(this.getClass().getName());
log.info("add account");