1、只需要在logback-spring.xml加上如下代码:
<!-- logstash远程日志配置-->
<appender name="stash" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>${logback.elk.address}</destination>
<encoder class="net.logstash.logback.encoder.LogstashEncoder" >
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{cname}:%X{cid},%X{uname}:%X{uid}] %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
${logback.elk.address}是logstash的地址加端口
2.在加上下面的
spring这边的配置就OK了。
3.manvan依赖
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>5.2</version>
</dependency>