SpringBoot2.0配置Logback并发送日志到ELK
https://note.youdao.com/ynoteshare1/index.html?id=37c3fe9e53a457781a185f3ed979ecae&type=note
附近请打开有道云笔记链接
一、添加logback-spring.xml到resources目录下,注意索引名称的配置
<!-- 如果需要区分环境,则定义多外logstash appender -->
<appender name="logstash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<!--模拟多个logstash-->
<destination>192.168.1.248:4560</destination>
<!--<destination>192.168.1.121:4560</destination>-->
<!--<destination>192.168.1.121:4560</destination>-->
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder">
<timeZone>UTC</timeZone>
<customFields>{"servicename":"qxs"}</customFields>
</encoder>
<!--<connectionStrategy>-->
<!--<roundRobin>-->
<!--<connectionTTL>5 minutes</connectionTTL>-->
<!--</roundRobin>-->
<!--</connectionStrategy>-->
</appender>
二、在pom.xml中添加依赖
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>5.0</version>
</dependency>
三、启动项目,然后在kibana管理后台配置对应的索引,即可查看
四、参考文章