What I want to achieve:
- configure from logback-spring.xml or application.properties the elasticsearch index in which the logs will end up.
What I tried:
- I am currently using this dependency:
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>7.3</version>
</dependency>
With this 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>
And on the logstash side, I am using this configuration:
output {
stdout {
codec => rubydebug
}
elasticsearch {
hosts => ["localhost:9200"]
index => theindex
}
}
Observation, I can see the logs in elasticsearch under the index theindex
Issue:
- Now, if I want to change the destination index, I need to modify directly the file and restart logstash.
Question:
- How can configure the destination index of the logs from the application.properties with something like (this is an example)
spring.logstash.index=someotherindexor directly from the logback.xml?