Logstash无法正确读取弹簧属性

时间:2018-11-26 08:36:01

标签: java spring logging logstash properties-file

因此,我有一个非常简单的logstash配置,该配置应从spring中读取主机URL。尽管由于某种原因它无法正常工作。

我的logback-spring.xml看起来像这样:

  <springProperty name="logstashDestination" scope="context" source="service.logstash.host"/>
  <appender class="net.logstash.logback.appender.LogstashTcpSocketAppender" name="LOGSTASH">
    <destination>${logstashDestination}</destination>

    <!-- encoder is required -->
    <encoder class="net.logstash.logback.encoder.LogstashEncoder">
      <customFields>{"service":"provisioning-engine-jane"}</customFields>
    </encoder>
  </appender>

在我的application.properties中,这些行如下:

spring.profiles.active:sit
service.logstash.host:NaN

application-sit.properties中,有以下一行:

service.logstash.host:api-test.local:9013

这会使整个应用程序因错误而崩溃

Exception in thread "restartedMain" java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.boot.devtools.restart.RestartLauncher.run(RestartLauncher.java:49)
Caused by: java.lang.IllegalStateException: Logback configuration error detected: 
ERROR in ch.qos.logback.core.joran.util.PropertySetter@44cb3536 - Could not invoke method addDestination in class net.logstash.logback.appender.LogstashTcpSocketAppender with parameter of type java.lang.String java.lang.reflect.InvocationTargetException
ERROR in net.logstash.logback.appender.LogstashTcpSocketAppender[LOGSTASH] - No destination was configured. Use <destination> to add one or more destinations to the appender

奇怪的是,如果我添加一个包含一些伪数据的bootstrap.properties文件,它将启动。这样做的问题是虚拟数据将覆盖我的环境特定的logstash URL。

任何人都知道为什么会发生这种情况吗?

0 个答案:

没有答案