简体   繁体   English

为什么我在Log4J中得到双倍输出?

[英]Why am I getting double like output in Log4J?

I am working on a Java Spring project and I want to log WARNS from every package and only INFO from my packages. 我正在一个Java Spring项目上工作,我想记录每个包中的WARNS,而只记录我包中的INFO。

I don't know why Log4J is giving me double line output for my packages. 我不知道为什么Log4J给我的软件包提供双行输出。

Can someone please tell me why 有人可以告诉我为什么吗

<?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="%d [%t] %-5p %c - %m%n"/>
        </layout>
    </appender>


    <logger name="com.xxxxx.mongodb">
        <level value="INFO"/>
        <appender-ref ref="console" />
    </logger>

    <root>
        <priority value="WARN"/>
        <appender-ref ref="console"/>
    </root>
</log4j:configuration>

Because your logger inherits the appenders from root logger. 因为您的记录器从根记录器继承了追加程序。

The docs for log4j state: log4j的文档状态:

The output of a log statement of logger C will go to all the appenders in C and its ancestors. 记录器C的日志语句的输出将传递给C中的所有附加器及其祖先。 This is the meaning of the term "appender additivity". 这就是术语“附加剂可加性”的含义。

However, if an ancestor of logger C, say P, has the additivity flag set to false, then C's output will be directed to all the appenders in C and its ancestors upto and including P but not the appenders in any of the ancestors of P. 但是,如果记录器C的祖先(例如P)的可加性标志设置为false,则C的输出将定向到C中的所有追加器及其直到包括P的祖先,但不定向到P的任何祖先的追加器。 。

Loggers have their additivity flag set to true by default. 记录器默认将其可加性标志设置为true。

Add

additivity="false"

attribute to the logger what is producing double output. 记录器会产生双倍输出。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM