.肯定是要进入相应的log4j包:log4j.x.jar包

2.在web.xml写入上下文

 

  1. <context-param>  
  2.         <param-name>log4jConfigLocation</param-name>  
  3.        <param-value>/WEB-INF/log4j.properties</param-value>  
  4. </context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>  
  1. <context-param>  
  2.         <param-name>log4jConfigLocation</param-name>  
  3.        <param-value>/WEB-INF/log4j.properties</param-value>  
  4. </context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>  
<context-param>
	    <param-name>log4jConfigLocation</param-name>
	   <param-value>/WEB-INF/log4j.properties</param-value>
</context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener>

3.配置log4j.properties属性文件

 

  1. ################ FATAL, ERROR, WARN, INFO, DEBUG  
  2. log4j.rootLogger=WARN,stdout,D,E  
  3.   
  4. ### stdout ###  
  5. log4j.appender.stdout=org.apache.log4j.ConsoleAppender  
  6. log4j.appender.stdout.Target=System.out  
  7. log4j.appender.stdout.layout=org.apache.log4j.PatternLayout  
  8. log4j.appender.stdout.layout.ConversionPattern= %d{ABSOLUTE} %5p %c{1}:%L - %m%n  
  9.   
  10. ### logFile ###  
  11. ### save error to another file ###  
  12. log4j.appender.D=org.apache.log4j.DailyRollingFileAppender  
  13. log4j.appender.D.File=D:/logs/test-error.log  
  14. log4j.appender.D.Append=true  
  15. #error only in this file  
  16. log4j.appender.D.Threshold =WARN  
  17. log4j.appender.D.layout=org.apache.log4j.PatternLayout  
  18. log4j.appender.D.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%t:%r] - [%p]  %m%n  
  19. 然后在写一个class文件运行加可以了