logback GELF appender连接了两次

时间:2017-01-14 20:21:32

标签: java logging spring-boot configuration logback

我正在尝试设置Graylog / GELF。在本地,我的控制台appender只记录一次消息,但是在我的graylog服务器上,我看到两次相同的日志消息。我打开调试,我看到了:

15:04:53,223 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
15:04:53,223 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [CONSOLE]
15:04:53,223 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:04:53,229 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [biz.paluch.logging.gelf.logback.GelfLogbackAppender]
15:04:53,233 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [GELF]
15:05:13,615 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [GELF] to Logger[ROOT]
15:05:13,615 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [biz.paluch.logging.gelf.logback.GelfLogbackAppender]
15:05:13,615 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [GELF]
15:05:13,617 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [GELF] to Logger[ROOT]
15:05:13,617 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to WARN
15:05:13,617 |-INFO in ch.qos.logback.classic.jul.LevelChangePropagator@34341ee8 - Propagating WARN level on Logger[ROOT] onto the JUL framework
15:05:13,617 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [CONSOLE] to Logger[ROOT]
15:05:13,617 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.

我注意到“将名为[GELF]的追加器附加到Logger [ROOT]”出现两次,我假设这是为什么我只在Graylog上进行双重记录。

这是我的配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">

    <springProperty scope="context" name="appName" source="spring.application.name"/>
    <springProperty scope="context" name="gelfHost" source="gelf.host"/>
    <springProperty scope="context" name="gelfPort" source="gelf.port"/>

    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>%d{HH:mm:ss.SSS} [%thread] [%-5level] %logger{36} - %msg%n</pattern>
        </encoder>
    </appender>

    <!-- This 'if' action is to avoid this appender from failing before spring cloud config is fetched with the external properites we are looking for -->
    <if condition='isDefined("gelfHost")'>
        <then>
            <springProfile name="graylog">
                <appender name="GELF" class="biz.paluch.logging.gelf.logback.GelfLogbackAppender">
                    <graylogHost>${gelfHost}</graylogHost>
                    <graylogPort>${gelfPort}</graylogPort>
                    <version>1.1</version>

                    <!--<facility>java-test</facility>-->
                    <extractStackTrace>true</extractStackTrace>
                    <filterStackTrace>true</filterStackTrace>
                    <mdcProfiling>true</mdcProfiling>
                    <timestampPattern>yyyy-MM-dd HH:mm:ss,SSSS</timestampPattern>
                    <maximumMessageSize>32768</maximumMessageSize>

                    <originHost>${HOST}</originHost>
                    <!-- This are static fields -->
                    <additionalFields>application=${appName},env=${DEPLOYED_ENV:-${ENV}}</additionalFields>
                    <!-- Optional: Specify field types -->
                    <additionalFieldTypes>application=String,env=String</additionalFieldTypes>

                    <mdcFields>user.id</mdcFields>
                    <includeFullMdc>true</includeFullMdc>

                    <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
                        <level>${GRAYLOG_THRESHOLD:-INFO}</level>
                    </filter>
                </appender>

                <root>
                    <appender-ref ref="GELF" />
                </root>
            </springProfile>
        </then>
    </if>

    <root level="WARN">
        <appender-ref ref="CONSOLE" />
    </root>
</configuration>

为什么我的gelf appender似乎被创建/附加两次?

PS:我正在使用spring-boot,我的logback配置文件名为“logback-spring.xml”,它位于/ src / main / resources中。我还确认我的配置文件是类路径上唯一的logback配置。

0 个答案:

没有答案