logback整合Logstash
1.依赖
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>4.9</version>
</dependency>
2.配置
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender"> <destination>127.0.0.1:4560</destination> <!-- <encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder" /> --> <!-- 日志输出编码 --> <encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder"> <providers> <timestamp> <timeZone>UTC</timeZone> </timestamp> <pattern> <pattern> { "severity": "%level", "service": "${springAppName:-}", "trace": "%X{X-B3-TraceId:-}", "span": "%X{X-B3-SpanId:-}", "exportable": "%X{X-Span-Export:-}", "pid": "${PID:-}", "thread": "%thread", "class": "%logger{40}", "msg": "%message" } </pattern> </pattern> </providers> </encoder> </appender>
3.Logstash配置
input { tcp { port => 4560 codec => json_lines } } output{ elasticsearch { hosts => ["localhost:9200"] } stdout { codec => rubydebug } }
另:插件安装/logstash-plugin install logstash-codec-json_lines
4.kibana添加索引
Management->Create Index Pattern->输入logstash*