log4j2记录器级别无法正常工作

时间:2015-06-23 23:35:45

标签: java logging log4j log4j2 flume

我正在使用具有以下配置的log4j2。记录器“org.apache.solr”使用level =“info”定义,但我也可以在日志文件中看到错误消息。我要确保的是,只有包“org.apache.solr。*”的信息级日志被发送到水槽,其余的记录到tomcat.log。

<?xml version="1.0" encoding="UTF-8" ?>
<Configuration status="INFO">
<Appenders>
<RollingRandomAccessFile name="tomcatLog" fileName="/home/jim/logs/tomcat.log" filePattern="/home/jim/logs/$${date:yyyy-MM}/tomcat-%d{yyyy-MM-dd-HH}-%i.log.gz">
    <PatternLayout>
        <Pattern>%d{dd MMM yyyy HH:mm:ss,SSS} %t %p %c{1.} [%F - %L] %m%n</Pattern>
    </PatternLayout>

    <Policies>
        <TimeBasedTriggeringPolicy interval="6" modulate="true"/>
        <SizeBasedTriggeringPolicy size="250 MB"/>
    </Policies>
</RollingRandomAccessFile>

<Flume name="solrEventLogger" compress="false">
    <Property name="channel.type">file</Property>
    <Property name="channel.checkpointDir">/home/jim/logs/solr/checkpoint</Property>
    <Property name="channel.dataDirs">/home/jim/logs/solr/data</Property>

    <Property name="sinks">agent1</Property>
    <Property name="agent1.channel">file</Property>
    <Property name="agent1.type">avro</Property>
    <Property name="agent1.hostname">127.0.0.1</Property>
    <Property name="agent1.port">61237</Property>
    <Property name="agent1.batch-size">1</Property>
            <PatternLayout>
                    <Pattern>%d{dd MMM yyyy HH:mm:ss,SSS} %t %p %c{1.} [%F - %L] %m%n</Pattern>
            </PatternLayout>

    <Property name="processor.type">failover</Property>
</Flume>
</Appenders>
<Loggers>
  <Logger name="org.apache.solr" additivity="true" level="info">
    <AppenderRef ref="solrEventLogger" />
  </Logger>
  <Root level="warn">
    <AppenderRef ref="tomcatLog"/>
  </Root>
</Loggers>
</Configuration>

1 个答案:

答案 0 :(得分:2)

级别API指定允许通过配置级别和更具体级别的消息。因此,指定level = info,允许警告通过。