Spring Boot微服务未将日志推送到Logstash

时间:2019-05-09 16:51:09

标签: java spring-boot logstash microservices elastic-stack

我有一个微服务,它不将日志推送到logstash

对于集中式日志记录,我使用的是运行在Docker容器中的ELK堆栈

我在春季启动代码中使用logback.xml

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

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

    <appender name="STASH"
        class="net.logstash.logback.appender.LogstashTcpSocketAppender">
        <destination>192.168.99.100:5045</destination>



        <encoder
            class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
            <providers>
                <mdc /> <!-- MDC variables on the Thread will be written as JSON fields -->
                <context /> <!--Outputs entries from logback's context -->
                <version /> <!-- Logstash json format version, the @version field in the output -->
                <logLevel />
                <loggerName />

                <pattern>
                    <pattern>
                        {
                        "serviceName": "order-service"
                        }
                    </pattern>
                </pattern>

                <threadName />
                <message />
                <logstashMarkers />
                <stackTrace />
            </providers>
        </encoder>
    </appender>

    <root level="info">
        <appender-ref ref="STDOUT" />
        <appender-ref ref="STASH" />
    </root>
</configuration>

这是我的logstash.conf文件

input {
    tcp {
        port => 5045
        codec => json
   }
}

output {
    stdout { codec => rubydebug }
    elasticsearch {
        hosts => [ "http://192.168.99.100:9200" ]
        index => "micro-%{serviceName}"
    }
}

因此,当我尝试在Kibana中创建索引时,没有任何结果。

对此有任何帮助

0 个答案:

没有答案