<dependency>
<groupId>net.logstash.logbackgroupId>
<artifactId>logstash-logback-encoderartifactId>
<version>6.5version>
dependency>
确认自己项目中是否存在 jackson依赖,一般情况下,如果有 redission、nacos的依赖就不需要引用。
注意logback的版本和jackson得版本存在关联差异性。我这边的对照版本是 jackson 2.11.4 => logback 6.5
<included>
<springProperty scope="context" name="logstash.ips" source="jamel.logstash.ips" defaultValue="127.0.0.1:5044"/>
<springProperty scope="context" name="logstash.connectionTTL" source="jamel.logstash.connectionTTL"
defaultValue="5 minutes"/>
<appender name="LOGSTASH_APPENDER" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<includeCallerData>trueincludeCallerData>
<destination>${logstash.ips}destination>
<encoder charset="UTF-8" class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<pattern>
<omitEmptyFields>trueomitEmptyFields>
<pattern>
{
"severName": "${spring.application.name}",
"severIp": "%ip",
"userId": "%userId",
"port": "${server.port}",
"level": "%p",
"marker": "%xMarker",
"method": "%xLogger.%xMethod:%xLine",
"message": "%m",
"exception": "${LOG_EXCEPTION_CONVERSION_WORD:-%wEx}",
"createTime": "%d{yyyy-MM-dd HH:mm:ss.SSS}"
}
pattern>
pattern>
providers>
encoder>
<connectionStrategy>
<roundRobin>
<connectionTTL>${logstash.connectionTTL}connectionTTL>
roundRobin>
connectionStrategy>
appender>
included>
<configuration>
<include resource="com/jamel/log/xml/defaults.xml"/>
<include resource="com/jamel/log/xml/defaults-logstash.xml"/>
<springProfile name="dev,prod">
<root level="${log.level.console}">
<appender-ref ref="LOGSTASH_APPENDER"/>
root>
springProfile>
configuration>
jamel:
logstash:
ips: 47.107.76.32:5044
查看kibana情况,至此表示日志已经从springboot推送到es。可以通过kibana查看