我正在尝试在kubernetes上部署ELK,但是我坚持使用logback configure。 Logback应该将日志发送到logstash,但它忽略了logback.xml
该文件的内容:
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="true">
<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>logstash:5000</destination>
<encoder
class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<mdc/>
<context/>
<version/>
<logLevel/>
<loggerName/>
<pattern>
<pattern>
{
"serviceName": "account-service"
}
</pattern>
</pattern>
<threadName/>
<message/>
<logstashMarkers/>
<stackTrace/>
</providers>
</encoder>
</appender>
<root level="info">
<appender-ref ref="STDOUT"/>
<appender-ref ref="STASH"/>
</root>
</configuration>
在本地它可以工作,使用docker也可以。但是,如果我将其部署到kubernetes,spring将忽略该文件。
要部署,我正在使用该dockerfile:
FROM openjdk:11-jre
ADD build/libs/account-service-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-Dspring.profiles.active=prod",-jar","/app.jar"]
属性通过云配置获取。我什至尝试将其添加到account-service-prod.yml:
logging:
path: classpath:logback.xml