.肯定是要进入相应的log4j包:log4j.x.jar包
2.在web.xml写入上下文
- <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>
- <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>
<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属性文件
- ################ FATAL, ERROR, WARN, INFO, DEBUG
- log4j.rootLogger=WARN,stdout,D,E
- ### stdout ###
- log4j.appender.stdout=org.apache.log4j.ConsoleAppender
- log4j.appender.stdout.Target=System.out
- log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
- log4j.appender.stdout.layout.ConversionPattern= %d{ABSOLUTE} %5p %c{1}:%L - %m%n
- ### logFile ###
- ### save error to another file ###
- log4j.appender.D=org.apache.log4j.DailyRollingFileAppender
- log4j.appender.D.File=D:/logs/test-error.log
- log4j.appender.D.Append=true
- #error only in this file
- log4j.appender.D.Threshold =WARN
- log4j.appender.D.layout=org.apache.log4j.PatternLayout
- log4j.appender.D.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss} [%t:%r] - [%p] %m%n
- 然后在写一个class文件运行加可以了