<!-- log4j --> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>1.2.17</version> </dependency>
<context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:com/nanri/config/logConfig/log4j.properties</param-value> </context-param> <!-- 应用名.root 相当于添加一个系统变量,主要是为了指定应用的路径。 --> <context-param> <param-name>webAppRootKey</param-name> <param-value>SpringProject.root</param-value> </context-param>
SpringProject.root是在web.xml中配置的webAppRootKey的值。
#配置日志文件的存储地址 log4jPath=${SpringProject.root}/WEB-INF/logs/ log4j.rootLogger=info, dest1 log4j.appender.dest1.encoding=UTF-8 log4j.appender.dest1=org.apache.log4j.ConsoleAppender log4j.appender.dest1.Append=true log4j.appender.dest1.layout=org.apache.log4j.PatternLayout log4j.appender.dest1.layout.ConversionPattern=%d{[yyyy-MM-dd HH:mm:ss]} %-5p %x -> %m%n ###############################################product.log################################################ #对包pakage.product下所有的类配置一个日志文件 log4j.logger.pakage.product=info,productFile log4j.additivity.pakage.product=false log4j.appender.productFile.encoding=UTF-8 log4j.appender.productFile=org.apache.log4j.FileAppender log4j.appender.productFile.File=${log4jPath}/pakage/product/product.log log4j.appender.productFile.Append=true log4j.appender.productFile.layout=org.apache.log4j.PatternLayout log4j.appender.productFile.layout.ConversionPattern=%d %-5p %-5c{10}:%L %x -> %m%
原文:http://www.cnblogs.com/wuchaodzxx/p/7142619.html