无法禁用log4j2中来自第三方jar的日志

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法禁用log4j2中来自第三方jar的日志相关的知识,希望对你有一定的参考价值。

我正在使用log4j2 kafka附加程序,并从“ org.apache.kafka”中获取过多日志记录,例如:

16:30:48.215 [main] DEBUG o.a.kafka.common.metrics.Metrics - Added sensor with name failed-authentication:
16:30:48.216 [main] DEBUG o.a.kafka.common.metrics.Metrics - Added sensor with name bytes-sent-received:
16:30:48.216 [main] DEBUG o.a.kafka.common.metrics.Metrics - Added sensor with name bytes-sent:
16:30:48.217 [main] DEBUG o.a.kafka.common.metrics.Metrics - Added sensor with name bytes-received:
16:30:48.217 [main] DEBUG o.a.kafka.common.metrics.Metrics - Added sensor with name select-time:
16:30:48.218 [main] DEBUG o.a.kafka.common.metrics.Metrics - Added sensor with name io-time:
16:30:48.219 [main] DEBUG o.a.kafka.common.metrics.Metrics - Added sensor with name batch-size
16:30:48.219 [main] DEBUG o.a.kafka.common.metrics.Metrics - Added sensor with name compression-rate

我仅使用log4j2.xml进行配置,除用于控制台的此输出外,它对我所有其他附加程序都适用。我尝试使用以下方法关闭此kafka记录器:

<Logger name="org.apache.kafka" level="off" additivity="false"/>

但是没有成功。我什至试图关闭整个输出到控制台,但是此日志一直显示。

有人对此问题有何建议?难道我做错了什么?这是我的整个log4j2.xml配置,仍然显示kafka日志记录:

<Configuration monitorInterval="30" status="WARN">
<Properties>
    <Property name="baseLogPath">/opt/taptica/trk/logs/</Property>
    <Property name="hitsPath">/etl_files/004/</Property>
    <Property name="conversionsPath">/etl_files_conversions/004/</Property>
    <Property name="postBackPath">/postBack/</Property>
    <Property name="statisticsPath">/opt/taptica/trk/logs/statistics/</Property>
    <!-- <Property name="hostName">$env:HOSTNAME</Property> -->
    <Property name="kafkaProducers">
        kafka-prod-01.nyj.taptica.info:9092,kafka-prod-02.nyj.taptica.info:9092,kafka-prod-03.nyj.taptica.info:9092
    </Property>
    <Property name="patternTemplae">
        "timestamp":"%ddd MMM yyyy HH:mm:ss.SSS","app":"Tracker","level":"%-5level","thread":"%thread","class":"%logger1"%message%n
    </Property>
</Properties>
<Filters>
    <MarkerFilter marker="SQL" onMatch="NEUTRAL" onMismatch="NEUTRAL"/>
</Filters>
<Appenders>
    <Console name="Console" target="SYSTEM_OUT">
        <PatternLayout>
            <Pattern>$patternTemplae</Pattern>
        </PatternLayout>
    </Console>
    <RollingRandomAccessFile name="TrkLog" fileName="$baseLogPathtrk.log" filePattern="baseLogPathtrk-%dMM-dd-yyyy@HH:mm-%i.log.gz">
        <PatternLayout>
            <Pattern>$patternTemplae</Pattern>
        </PatternLayout>
        <Policies>
            <SizeBasedTriggeringPolicy size="500 MB"/>
        </Policies>
        <DefaultRolloverStrategy max="100"/>
    </RollingRandomAccessFile>
    <RollingRandomAccessFile name="NettyLog" fileName="$baseLogPathnetty.log" filePattern="baseLogPathnetty-%dMM-dd-yyyy@HH:mm-%i.log.gz">
        <PatternLayout>
            <Pattern>$patternTemplae</Pattern>
        </PatternLayout>
        <Policies>
            <SizeBasedTriggeringPolicy size="500 MB"/>
        </Policies>
        <DefaultRolloverStrategy max="100"/>
    </RollingRandomAccessFile>
    <RollingRandomAccessFile name="FilterLog" fileName="$baseLogPathfilter.log" filePattern="baseLogPathfilter-%dMM-dd-yyyy@HH:mm-%i.log.gz">
        <PatternLayout>
            <Pattern>$patternTemplae</Pattern>
        </PatternLayout>
        <Policies>
            <SizeBasedTriggeringPolicy size="500 MB"/>
        </Policies>
        <DefaultRolloverStrategy max="100"/>
    </RollingRandomAccessFile>
    <RollingRandomAccessFile name="RequestFile" fileName="$baseLogPathrequest.log" filePattern="baseLogPathrequest-%dMM-dd-yyyy@HH:mm-%i.log.gz">
        <PatternLayout>
            <Pattern>$patternTemplae</Pattern>
        </PatternLayout>
        <Policies>
            <SizeBasedTriggeringPolicy size="500 MB"/>
        </Policies>
        <DefaultRolloverStrategy max="100"/>
    </RollingRandomAccessFile>
    <RollingRandomAccessFile name="ResponseFile" fileName="$baseLogPathresponse.log" filePattern="baseLogPathresponse-%dMM-dd-yyyy@HH:mm-%i.log.gz">
        <PatternLayout>
            <Pattern>$patternTemplae</Pattern>
        </PatternLayout>
        <Policies>
            <SizeBasedTriggeringPolicy size="500 MB"/>
        </Policies>
        <DefaultRolloverStrategy max="100"/>
    </RollingRandomAccessFile>
    <!-- Pixel Appender -->
    <RollingRandomAccessFile name="t1PixelFile" fileName="$baseLogPatht1pixel.log" filePattern="$hitsPatht1pixel_%dMM-dd-yyyy-HH-mm-ss-SSS.gz" immediateFlush="false">
        <Policies>
            <SizeBasedTriggeringPolicy size="5 MB"/>
        </Policies>
        <DefaultRolloverStrategy max="200"/>
    </RollingRandomAccessFile>
    <!-- Impression Appender -->
    <RollingRandomAccessFile name="t1ImpressionFile" fileName="$baseLogPatht1impression.log" filePattern="$hitsPatht1imp_%dMM-dd-yyyy-HH-mm-ss-SSS.gz" immediateFlush="true">
        <Policies>
            <SizeBasedTriggeringPolicy size="5 MB"/>
            <TimeBasedTriggeringPolicy interval="10000" modulate="true"/>
        </Policies>
        <DefaultRolloverStrategy max="200"/>
    </RollingRandomAccessFile>
    <!-- Click Appender -->
    <RollingRandomAccessFile name="t1ClickFile" fileName="$baseLogPatht1click.log" filePattern="$hitsPatht1click_%dMM-dd-yyyy-HH-mm-ss%i.gz" immediateFlush="true">
        <Policies>
            <SizeBasedTriggeringPolicy size="10 MB"/>
        </Policies>
        <DefaultRolloverStrategy max="200"/>
    </RollingRandomAccessFile>
    <!-- Conversion Appender -->
    <RollingRandomAccessFile name="t1ConversionFile" fileName="$baseLogPatht1conversion.log" filePattern="$conversionsPatht1conv_%dMM-dd-yyyy-HH-mm-ss-SSS.gz" immediateFlush="true">
        <Policies>
            <SizeBasedTriggeringPolicy size="5 MB"/>
        </Policies>
        <DefaultRolloverStrategy max="200"/>
    </RollingRandomAccessFile>
    <!-- Goal Appender -->
    <RollingRandomAccessFile name="t1GoalFile" fileName="$baseLogPatht1goal.log" filePattern="$conversionsPatht1goal_%dMM-dd-yyyy-HH-mm-ss-SSS.gz" immediateFlush="true">
        <Policies>
            <SizeBasedTriggeringPolicy size="5 MB"/>
            <TimeBasedTriggeringPolicy interval="10000" modulate="true"/>
        </Policies>
        <DefaultRolloverStrategy max="200"/>
    </RollingRandomAccessFile>
    <!-- RTB Click Appender -->
    <RollingRandomAccessFile name="rtbClickFile" fileName="$baseLogPathrtbclick.log" filePattern="$hitsPathrtbclick_%dMM-dd-yyyy-HH-mm-ss-SSS.gz" immediateFlush="true">
        <Policies>
            <SizeBasedTriggeringPolicy size="5 MB"/>
            <TimeBasedTriggeringPolicy interval="10000" modulate="true"/>
        </Policies>
        <DefaultRolloverStrategy max="200"/>
    </RollingRandomAccessFile>
    <!-- RTB Impression Appender -->
    <RollingRandomAccessFile name="rtbImpressionFile" fileName="$baseLogPathrtbimpression.log" filePattern="$hitsPathrtbimp_%dMM-dd-yyyy-HH-mm-ss-SSS.gz" immediateFlush="false">
        <Policies>
            <SizeBasedTriggeringPolicy size="5 MB"/>
            <TimeBasedTriggeringPolicy interval="10000" modulate="true"/>
        </Policies>
        <DefaultRolloverStrategy max="200"/>
    </RollingRandomAccessFile>
    <!-- Click Statistics Appender -->
    <RollingRandomAccessFile name="eventStatisticsFile" fileName="$baseLogPatheventStatistics.log" filePattern="$statisticsPathevent_%dMM-dd-yyyy-HH-mm.gz" immediateFlush="false">
        <Policies>
            <TimeBasedTriggeringPolicy interval="5" modulate="true"/>
        </Policies>
        <DefaultRolloverStrategy max="200"/>
    </RollingRandomAccessFile>
    <!-- Budget Appender Kafka -->
    <Kafka name="t1BudgetKafka" topic="budget_main" syncSend="true">
        <PatternLayout pattern="%message"/>
        <Property name="bootstrap.servers">$kafkaProducers</Property>
    </Kafka>
    <!-- Postback Appender -->
    <Kafka name="Kafka" topic="postback" syncSend="true">
        <PatternLayout pattern="%message"/>
        <Property name="bootstrap.servers">$kafkaProducers</Property>
    </Kafka>
    <!-- Filter statistics Appender Kafka -->
    <Kafka name="filterStatisticsAppender" topic="tracker_filter_statistics" syncSend="true">
        <PatternLayout pattern="%message"/>
        <Property name="bootstrap.servers">$kafkaProducers</Property>
    </Kafka>
    <!-- Goal Appender Kafka -->
    <Kafka name="t1GoalKafka" topic="goals_main" syncSend="true">
        <PatternLayout pattern="%message"/>
        <Property name="bootstrap.servers">$kafkaProducers</Property>
    </Kafka>
    <!-- Click Appender Kafka -->
    <Kafka name="t1ClickKafka" topic="clicks_main" syncSend="true">
        <PatternLayout pattern="%message"/>
        <Property name="bootstrap.servers">$kafkaProducers</Property>
    </Kafka>
    <!-- Impression Appender Kafka -->
    <Kafka name="t1ImpressionKafka" topic="impressions_main" syncSend="true">
        <PatternLayout pattern="%message"/>
        <Property name="bootstrap.servers">$kafkaProducers</Property>
    </Kafka>
    <!-- Conversionn Appender Kafka -->
    <Kafka name="t1ConversionKafka" topic="conversions_main" syncSend="true">
        <PatternLayout pattern="%message"/>
        <Property name="bootstrap.servers">$kafkaProducers</Property>
    </Kafka>
</Appenders>
<Loggers>
    <Logger name="EventStatistics" level="info" additivity="false">
        <AppenderRef ref="eventStatisticsFile"/>
    </Logger>
    <Logger name="T1PixelHits" level="info" additivity="false">
        <AppenderRef ref="t1PixelFile"/>
    </Logger>
    <Logger name="T1ImpressionHits" level="info" additivity="false">
        <AppenderRef ref="t1ImpressionFile"/>
    </Logger>
    <Logger name="T1ImpressionHitsKafka" level="info" additivity="false">
        <AppenderRef ref="t1ImpressionKafka"/>
    </Logger>
    <Logger name="T1ClickHits" level="info" additivity="false">
        <AppenderRef ref="t1ClickFile"/>
    </Logger>
    <Logger name="T1ClickHitsKafka" level="info" additivity="false">
        <AppenderRef ref="t1ClickKafka"/>
    </Logger>
    <Logger name="T1ConversionHitsKafka" level="info" additivity="false">
        <AppenderRef ref="t1ConversionKafka"/>
    </Logger>
    <Logger name="T1ConversionHits" level="info" additivity="false">
        <AppenderRef ref="t1ConversionFile"/>
    </Logger>
    <Logger name="T1GoalHitsKafka" level="info" additivity="false">
        <AppenderRef ref="t1GoalKafka"/>
    </Logger>
    <Logger name="T1GoalHits" level="info" additivity="false">
        <AppenderRef ref="t1GoalFile"/>
    </Logger>
    <Logger name="RtbClickHits" level="info" additivity="false">
        <AppenderRef ref="rtbClickFile"/>
    </Logger>
    <Logger name="RtbImpressionHits" level="info" additivity="false">
        <AppenderRef ref="rtbImpressionFile"/>
    </Logger>
    <Logger name="ResponseLogger" level="info" additivity="false">
        <AppenderRef ref="ResponseFile"/>
    </Logger>
    <Logger name="RequestLogger" level="info" additivity="false">
        <AppenderRef ref="RequestFile"/>
    </Logger>
    <Logger name="filterLogger" level="INFO" additivity="false">
        <AppenderRef ref="FilterLog"/>
    </Logger>
    <Logger name="nettyLogger" level="error" additivity="false">
        <AppenderRef ref="NettyLog"/>
    </Logger>
    <Logger name="T1PostBackLogger" level="INFO" additivity="false">
        <AppenderRef ref="Kafka"/>
    </Logger>
    <Logger name="T1BudgetKafka" level="info" additivity="false">
        <AppenderRef ref="t1BudgetKafka"/>
    </Logger>
    <Logger name="FilterStatisticsKafkaProducer" level="INFO" additivity="false">
        <AppenderRef ref="filterStatisticsAppender"/>
    </Logger>
    <Logger name="org.apache.kafka" level="off" additivity="false"/>
    <Root level="off" additivity="false">
        <AppenderRef ref="Console"/>
        <AppenderRef ref="TrkLog"/>
    </Root>
</Loggers>

答案

[我想知道您是否能够解决此问题,因为我遇到了同样的问题,并且我正在采用几乎相同的解决方案,但它也不起作用:(同样对我来说。

以上是关于无法禁用log4j2中来自第三方jar的日志的主要内容,如果未能解决你的问题,请参考以下文章

log4j2项目打成jar包运行日志无法打印

记一次项目上线后Log4j2不输出日志的坑

从 logs4j 禁用 freemarker 日志

记一次Log4j2日志无法输出的 心酸史

log4j2使用入门——与不同日志框架的适配

log4j升级为log4j2(无需改动代码)