web.xml中配置log4j

时间:2021-04-30 01:42:48

1.将 commons-logging.jar和 log4j.jar加入你的项目中;
2.在src/下创建log4j.properties|log4j.xml文件;
3.在web.xml中配置log4j的信息,如下:
<context-param>
  <param-name>log4jConfigLocation</param-name>
  <param-value>/WEB-INF/classes/log4j.properties</param-value>
   </context-param>
<listener>
  <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>

注意:红色代码是固定的,log4jConfigLocation就是用来加载log4j文件的固定名。