2014-04-14 157 views
0

以下是我log4j.xml的結構:我想日誌生成Log4j的日誌過濾

<appender name="logfile" class="org.apache.log4j.DailyRollingFileAppender"> 
    <param name="File" value="somelog.log" /> 
    <param name="Append" value="true" /> 
    <param name="DatePattern" value="'.'yyyy-MM-dd-a" /> 
    <layout class="org.apache.log4j.PatternLayout"> 
     <param name="ConversionPattern" 
      value="%d{HH:mm:ss,SSS} %-5p [%t]: %c{1} (%X{RequestId}) - %m%n" /> 
    </layout> 
</appender> 

<appender name="exceptionServiceSoap" 
    class="org.apache.log4j.DailyRollingFileAppender"> 
    <param name="file" value="somelog1.log" /> 
    <param name="Append" value="true" /> 
    <param name="DatePattern" value="'.'yyyy-MM-dd-a" /> 
    <layout class="org.apache.log4j.PatternLayout"> 
     <param name="ConversionPattern" 
      value="%d{HH:mm:ss,SSS} %-5p [%t]: %c{1} (%X{RequestId}) - %m%n" /> 
    </layout> 
</appender> 

<logger name="org.codehaus.xfire" additivity="true"> 
      <level value="INFO" /> 
      <appender-ref ref="exceptionServiceSoap"/> 
</logger> 

<category name="org"> 
    <priority value="WARN" /> 
</category> 

<category name="org.hibernate.SQL"> 
    <priority value="ERROR" /> 
</category> 

<category name="com"> 
    <priority value="WARN" /> 
</category> 

<category name="httpclient"> 
    <priority value="WARN" /> 
</category>  

<root> 
    <appender-ref ref="logfile" /> 
</root> 

內包「org.codehaus.xfire」 d使用附加器「exceptionServiceSoap」和所有其他目的附加器應使用「logfile」,但以「org.codehaus.xfire」上方安裝日誌都在追加程序內部運行。我怎樣才能避免這種情況?

回答

0

我不是100%肯定,但你可以試試這個:

<Loggers> 
    <Logger name="org.codehaus.xfire" level="all" additivity="false"> 
     <AppenderRef ref="exceptionServiceSoap"/> 
    </Logger> 
    <Root level="all"> 
     <AppenderRef ref="logfile"/> 
    </Root> 
</Loggers> 

而且你的追加應在標籤內:<Appenders>...</Appenders>