【问题标题】:Logback destination configuration from application.yml来自 application.yml 的 Logback 目标配置
【发布时间】:2019-02-15 09:20:50
【问题描述】:

我正在尝试在 application.yml 的 XML 导入目标配置中配置我的 logback。

当我在 XML 中设置静态目标时,一切都很好,但如果不是,那么我在启动时会收到此异常:

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[STASH] - No destination was configured. Use <destination> to add one or more destinations to the appender

我的依赖:

  • spring-boot: '1.5.4.RELEASE'
  • net.logstash.logback:logstash-logback-encoder:4.9

logback-spring.xml

    <springProperty name="LOGBACK_URL" source="logback.destination.url"/>
    <springProperty name="LOGBACK_PORT" source="logback.destination.port"/>
    <appender name="STASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
        <destination>${LOGBACK_URL}:${LOGBACK_PORT}</destination>
        <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">...
        </encoder>
    </appender>

应用程序.yml

logback:
  destination:
    url: kibana.test
    port: 1234

我试图避免将此配置迁移到 java 并希望它是不必要的。提前致谢!

编辑

我已经通过在xml配置中添加默认值来解决这个问题,如下所示:

<destination>${LOGBACK_URL:- }:${LOGBACK_PORT:- }</destination>

【问题讨论】:

  • 您是否正在使用 docker-compose 运行 ELK 堆栈?我在这里遇到了一些与您的情况类似的问题(我使用的是 Maven)。没有任何内容被发送到 logstash。

标签: spring spring-boot logback


【解决方案1】:

把它留在这里给任何面临类似问题的人,就我而言,我不得不从目标标签内的 url 中删除 http://。

【讨论】:

    猜你喜欢
    • 2016-12-08
    • 1970-01-01
    • 2021-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-18
    相关资源
    最近更新 更多