Spring Boot配置logstash
1、添加logstash依赖
<dependency> <groupId>net.logstash.logback</groupId> <artifactId>logstash-logback-encoder</artifactId> <version>5.1</version> </dependency>
2、resources目录下创建logback-spring.xml文件
<?xml version="1.0" encoding="UTF-8"?> <configuration> <include resource="org/springframework/boot/logging/logback/base.xml" /> <property name="LOGSTASH_HOST" value="${LOGSTASH_HOST:-${DOCKER_HOST:-192.168.193.138}}" /> <property name="LOGSTASH_PORT" value="${LOGSTASH_PORT:-5000}" /> <appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender"> <destination>${LOGSTASH_HOST}:${LOGSTASH_PORT}</destination> <encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder" /> </appender> <root level="INFO"> <appender-ref ref="LOGSTASH" /> <appender-ref ref="CONSOLE" /> </root> </configuration>
3、在application.propertities中配置第二步的文件
logging.config=classpath:logback-spring.xml