log4j.properties的配置及對應web.xml中的配置

web.xml中加入

<!-- 以下3項參數與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.context.ContextLoaderListener</listener-class>
 </listener>
 
 <listener>
  <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
 </listener>  
  
<!-- end -->

 

log4j.properties中的配置

 # Global logging configuration  
log4j.rootLogger=info,debug,error,stdout,fileout  
 
#\u8C03\u8BD5\u4F7F\u7528\uFF0C\u914D\u7F6E\u6253\u5370common.log\u5177\u4F53\u7C7B\uFF0C\u6216\u5305\u5185\u65E5\u5FD7\u3002  
#log4j.logger \u4E0E log4j.category\u4E3A\u524D\u7F00\uFF0Ccommon\u5305\u540D\uFF0Ccommon.TestLog4j\u7C7B\u3002  
#log4j.logger.common=DEBUG  
#log4j.category.common.TestLog4j=debug  
 
# Console output...  
log4j.appender.stdout=org.apache.log4j.ConsoleAppender  
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout  
log4j.appender.stdout.layout.ConversionPattern=%d %5p (%F:%L) - %m%n  
#File output...  
log4j.appender.fileout=org.apache.log4j.DailyRollingFileAppender  
log4j.appender.fileout.file=c:/log.txt   
log4j.appender.fileout.DatePattern='.'yyyy-MM-dd'.log' 
log4j.appender.fileout.layout=org.apache.log4j.PatternLayout  
log4j.appender.fileout.layout.ConversionPattern=%d %5p (%F:%L) - %m%n  
log4j.appender.fileout.Threshold=INFO 
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章