Spring 中使用Log4j

来源:互联网 发布:软件代码保护 编辑:程序博客网 时间:2024/05/23 00:08

pom.xml配置

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.wodwl</groupId><artifactId>hello</artifactId><version>0.0.1-SNAPSHOT</version><packaging>war</packaging><dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>3.1.2.RELEASE</version></dependency><dependency><groupId>com.ibatis</groupId><artifactId>ibatis-sqlmap</artifactId><version>2.1.0.565</version></dependency><dependency><groupId>jetty</groupId><artifactId>servlet-api</artifactId><version>2.5-6.0.2</version></dependency><dependency><groupId>velocity</groupId><artifactId>velocity</artifactId><version>1.5</version></dependency><dependency><groupId>log4j</groupId><artifactId>log4j</artifactId><version>1.2.17</version></dependency></dependencies></project>


web.xml配置

<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">  <display-name>hello</display-name>  <welcome-file-list>    <welcome-file>index.html</welcome-file>    <welcome-file>index.htm</welcome-file>    <welcome-file>index.jsp</welcome-file>    <welcome-file>default.html</welcome-file>    <welcome-file>default.htm</welcome-file>    <welcome-file>default.jsp</welcome-file>  </welcome-file-list>  <servlet>         <servlet-name>spring</servlet-name>         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>     </servlet>     <servlet-mapping>         <servlet-name>spring</servlet-name>         <url-pattern>*.do</url-pattern>     </servlet-mapping>             <context-param>  <param-name>webAppRootKey</param-name>  <param-value>webApp.root</param-value> </context-param>  <context-param>  <param-name>log4jConfigLocation</param-name>  <param-value>/WEB-INF/log4j.properties</param-value> </context-param>   <context-param>      <param-name>log4jRefreshInterval</param-name>      <param-value>60000</param-value>   </context-param>      <listener>      <listener-class>        org.springframework.web.util.Log4jConfigListener      </listener-class>   </listener></web-app>


在类中使用Log4j

 private static Logger logger = Logger.getLogger(ClassName.class);

logger.info("hello world");



原创粉丝点击