log4j - How to parse output to multiple files

Thanks, I find the below segment from log4j manual

----Note that filtering is only supported by the DOMConfigurator. The PropertyConfigurator does not support filters. That's a reason for me to migrate from log4j.properties to 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="console" class="org.apache.log4j.ConsoleAppender">
        
<layout class="org.apache.log4j.PatternLayout">
            
<param name="ConversionPattern" value="%m" />
        
</layout>
    
</appender>
    
    
<appender name="debug.file" class="org.apache.log4j.RollingFileAppender">
        
<param name="File" value="app.debug.log" />
        
<param name="Append" value="false" />
        
<param name="Encoding" value="UTF-8" />
        
<param name="ImmediateFlush" value="true" />
        
<param name="MaxFileSize" value="1MB" />
        
<layout class="org.apache.log4j.PatternLayout">
            
<param name="ConversionPattern" value="%m" />
        
</layout>
        
<filter class="org.apache.log4j.varia.LevelRangeFilter">
            
<param name="levelMin" value="DEBUG" />
            
<param name="levelMax" value="DEBUG" /> 
            
<param name="acceptOnMatch" value="true" />
        
</filter>
    
</appender>
        
    
<appender name="info.console" class="org.apache.log4j.ConsoleAppender">
        
<layout class="org.apache.log4j.PatternLayout">
            
<param name="ConversionPattern" value="%m" />
        
</layout>
        
<filter class="org.apache.log4j.varia.LevelRangeFilter">
            
<param name="levelMin" value="INFO" />
            
<param name="levelMax" value="FATAL" /> 
            
<param name="acceptOnMatch" value="false" />
        
</filter>
    
</appender>

    
<appender name="info.file" class="org.apache.log4j.RollingFileAppender">
        
<param name="File" value="app.info.log" />
        
<param name="Append" value="true" />
        
<param name="ImmediateFlush" value="true" />
        
<param name="MaxFileSize" value="10MB" />
        
<layout class="org.apache.log4j.PatternLayout">
            
<param name="ConversionPattern" value="%m" />
        
</layout>
        
<filter class="org.apache.log4j.varia.LevelRangeFilter">
            
<param name="levelMin" value="INFO" />
            
<param name="levelMax" value="INFO" /> 
            
<param name="acceptOnMatch" value="true" />
        
</filter>
    
</appender>

    
<logger name="net.alsan" additivity="false">
        
<level value="DEBUG" />
        
<appender-ref ref="debug.file" />
        
<appender-ref ref="info.console" />
    
</logger>
    
    
<root>
        
<level value="ERROR" />
        
<appender-ref ref="console" />
    
</root>
</log4j:configuration>

posted on 2005-06-12 15:47 毒菇求Buy 阅读(422) 评论(0)  编辑 收藏 引用 所属分类: JAVAXML

只有注册用户登录后才能发表评论。
<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

导航

统计

常用链接

留言簿(7)

随笔分类(133)

随笔档案(111)

文章分类(65)

文章档案(53)

相册

收藏夹(30)

BLOG

Book store

Graphics Design

搜索

最新评论

阅读排行榜

评论排行榜