如何使用logstash forwarder指定elasticsearch索引

问题描述 投票:0回答:0

我想达到的目标:

  • 从 logback-spring.xml 或 application.properties 配置日志将在其中结束的弹性搜索索引。

我尝试了什么:

  • 我目前正在使用这个依赖项:
<dependency>
            <groupId>net.logstash.logback</groupId>
            <artifactId>logstash-logback-encoder</artifactId>
            <version>7.3</version>
        </dependency>

有了这个 logback.xml:

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

    <appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
        <encoder class="net.logstash.logback.encoder.LogstashEncoder"/>
        <destination>the-logstash.com:5000</destination>
    </appender>

    <root level="INFO">
        <appender-ref ref="LOGSTASH"/>
    </root>

</configuration>

在 logstash 方面,我使用的是这个配置:

output {
  stdout {
    codec => rubydebug
  }
 
  elasticsearch {
    hosts => ["localhost:9200"]
    index => theindex
  }
}

观察,在索引theindex下可以看到elasticsearch中的日志

问题:

  • 现在,如果我想更改目标索引,我需要直接修改文件并重新启动 logstash。

问题:

  • 如何从 application.properties 配置日志的目标索引(这是一个示例)
    spring.logstash.index=someotherindex
    或直接从 logback.xml?
spring-boot elasticsearch logstash logstash-configuration logstash-forwarder
© www.soinside.com 2019 - 2024. All rights reserved.