duansky'weblog

统计

留言簿(3)

友情链接

阅读排行榜

评论排行榜

log4j配置文件(xml版)[原创]

<? xml version="1.0" encoding="UTF-8"  ?>
<! DOCTYPE log4j:configuration SYSTEM "log4j.dtd" >
< log4j:configuration  xmlns:log4j ='http://jakarta.apache.org/log4j/'>

    
<appender name ="STDOUT"  class ="org.apache.log4j.ConsoleAppender" >
        
< layout  class ="org.apache.log4j.PatternLayout" >
            
< param  name ="ConversionPattern"
                value
="[%-5p]%d{yyyy-MM-dd HH:mm:ss}[%l]: %m%n"   />
        
</ layout >
    
</ appender >

    
< appender  name ="DEBUG"
        class
="org.apache.log4j.DailyRollingFileAppender" >
        
< param  name ="File"
            value
="${catalina.home}/bin/config/log/debug/cs-debug.log"   />
        
< param  name ="Append"  value ="true"   />
        
< param  name ="DatePattern"  value =".yyyy-MM-dd"   />
        
< layout  class ="org.apache.log4j.PatternLayout" >
            
< param  name ="ConversionPattern"
                value
="[%-5p]%d{yyyy-MM-dd HH:mm:ss}[%C(%M:%L)]: %m%n"   />
        
</ layout >
        
< filter  class ="org.apache.log4j.varia.LevelRangeFilter" >
            
< param  name ="LevelMin"  value ="DEBUG"   />
            
< param  name ="LevelMax"  value ="DEBUG"   />
        
</ filter >
    
</ appender >

    
< appender  name ="INFO"
        class
="org.apache.log4j.DailyRollingFileAppender" >
        
< param  name ="File"
            value
="${catalina.home}/bin/config/log/info/cs-info.log"   />
        
< param  name ="Append"  value ="true"   />
        
< param  name ="DatePattern"  value =".yyyy-MM-dd"   />
        
< layout  class ="org.apache.log4j.PatternLayout" >
            
< param  name ="ConversionPattern"
                value
="[%-5p]%d{yyyy-MM-dd HH:mm:ss}[%C(%M:%L)]: %m%n"   />
        
</ layout >
        
< filter  class ="org.apache.log4j.varia.LevelRangeFilter" >
            
< param  name ="LevelMin"  value ="INFO"   />
            
< param  name ="LevelMax"  value ="INFO"   />
        
</ filter >
    
</ appender >

    
< appender  name ="WARN"
        class
="org.apache.log4j.DailyRollingFileAppender" >
        
< param  name ="File"
            value
="${catalina.home}/bin/config/log/warn/cs-warn.log"   />
        
< param  name ="Append"  value ="true"   />
        
< param  name ="DatePattern"  value =".yyyy-MM-dd"   />
        
< layout  class ="org.apache.log4j.PatternLayout" >
            
< param  name ="ConversionPattern"
                value
="[%-5p]%d{yyyy-MM-dd HH:mm:ss}[%C(%M:%L)]: %m%n"   />
        
</ layout >
        
< filter  class ="org.apache.log4j.varia.LevelRangeFilter" >
            
< param  name ="LevelMin"  value ="WARN"   />
            
< param  name ="LevelMax"  value ="WARN"   />
        
</ filter >
    
</ appender >

    
< appender  name ="ERROR"
        class
="org.apache.log4j.DailyRollingFileAppender" >
        
< param  name ="File"
            value
="${catalina.home}/bin/config/log/error/cs-error.log"   />
        
< param  name ="Append"  value ="true"   />
        
< param  name ="DatePattern"  value =".yyyy-MM-dd"   />
        
< layout  class ="org.apache.log4j.PatternLayout" >
            
< param  name ="ConversionPattern"
                value
="[%-5p]%d{yyyy-MM-dd HH:mm:ss}[%C(%M:%L)]: %m%n"   />
        
</ layout >
        
< filter  class ="org.apache.log4j.varia.LevelRangeFilter" >
            
< param  name ="LevelMin"  value ="ERROR"   />
            
< param  name ="LevelMax"  value ="ERROR"   />
        
</ filter >
    
</ appender >
    
    
< root >
        
< priority  value ="debug"   />
        
< appender-ref  ref ="STDOUT"   />
        
< appender-ref  ref ="DEBUG"   />
        
< appender-ref  ref ="INFO"   />
        
< appender-ref  ref ="WARN"   />
        
< appender-ref  ref ="ERROR"   />
    
</ root >

</ log4j:configuration >

保存为log4j.xml,并放置在src目录下(eclipse会自动编译到classes目录)
在tomcat的bin目录创建config\log目录,并在log目录下分别创建debug、info、warn、error目录
不同级别的日志会分别输出到各自对应的日志文件中
OK~

PS: <param name="File"
   value="${catalina.home}/bin/config/log/debug/cs-debug.log" />中的value我想替换成value="${log.dir}/debug/cs-debug.log",也就是说让log.dir="${catalina.home}/bin/config/log"。
log4j.properties文件中可以这样设置
log_dir=${catalina.home}/bin/config/log

但log4j.xml文件该怎么样配置呢?有知道的朋友麻烦回复一个~ 感激不尽

posted on 2008-09-12 10:00 duansky 阅读(919) 评论(0)  编辑  收藏 所属分类: Java


只有注册用户登录后才能发表评论。


网站导航: