1,在项目pom.xml文件中加上依赖:
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>4.8</version>
</dependency>
2,在项目logback.xml配置文件中加入一下代码:
<appender name="stash"
class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>127.0.0.1:4560</destination>
<!-- encoder is required -->
<encoder class="net.logstash.logback.encoder.LogstashEncoder" />
</appender>
和下面:
<root level="INFO">
<appender-ref ref="console" />
<appender-ref ref="rollingFile" />
<appender-ref ref="errorAppender" />
<appender-ref ref="OTHERPLACE"/>
<appender-ref ref="stash"/>
</root>
3,logstash bin 目录下的配置文件***.conf文件中:
input {
tcp {
port => 4560
codec => json_lines
}
}
output{
elasticsearch {
host => "localhost"
port => "9200"
protocol => "http"
index => "logstash-test"
}
}