0.工程是普通java web工程,不是maven工程.需要升级log4j
步骤发下:
1. 在build path中 移除项目对log4j-1.2.6.jar的引用,并物理删除log4j-1.2.6.jar文件
2.复制下面4个文件到WEB-INF/lib下
- log4j-core-2.9.0.jar
- log4j-api-2.9.0.jar
- log4j-1.2-api-2.9.0.jar
- log4j-web-2.9.0.jar
3.在build path中添加对 上面复制的4个文件的引用
4.修正web.xml文件
<!-- ***** log4j ***** --> <!-- <context-param> <param-name>webAppRootKey</param-name> <param-value>bookliner.root</param-value> </context-param> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>classpath:log4j-unittest.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> --> <!-- log4j2-begin --> <context-param> <param-name>log4jConfiguration</param-name> <param-value>classpath:log4j2.xml</param-value> </context-param> <listener> <listener-class>org.apache.logging.log4j.web.Log4jServletContextListener</listener-class> </listener> <filter> <filter-name>log4jServletFilter</filter-name> <filter-class>org.apache.logging.log4j.web.Log4jServletFilter</filter-class> </filter> <filter-mapping> <filter-name>log4jServletFilter</filter-name> <url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher> <dispatcher>INCLUDE</dispatcher> <dispatcher>ERROR</dispatcher> </filter-mapping> <!-- log4j2-end -->
5.根据原来的log4j.xml来编写log4j2.xml文件(内容略), 删除log4j.xml.
上记5步即可完成log4j的升级
PS:
jar文件下载
在 http://mvnrepository.com/ 中搜索, 搜索时不用带版本号,本来这个网站是提供maven依赖的,但是也提供了jar的下载
参考:
Using Log4j 2 in Web Applications