log4j2 logger levels not working

1.8k views Asked by At

I am using log4j2 with below configuration. The logger "org.apache.solr" is defined with level="info", but i can see error messages also in the log file. What i am trying to ensure is that only info level logs for package "org.apache.solr.*" are sent to flume and remainder are logged to the 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

There are 1 answers

0
Jimm On

The Level API specifies that the messages of the configured level and more specific level will be allowed to pass. Hence, specifying level = info, allowed warn to pass.