安裝Elasticsearch、kibana、logstash,教程連接 安裝教程spring
在springBoot 項目下pom文件增長logStash 依賴包json
<!--logStash-->
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>5.3</version>
</dependency>
複製代碼
在springboot資源文件夾下增長log日誌數據配置文件 logback-spring.xmlspringboot
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<include resource="org/springframework/boot/logging/logback/base.xml" />
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<!--配置logStash 服務地址-->
<destination>192.168.92.50:4560</destination>
<!-- 日誌輸出編碼 -->
<encoder charset="UTF-8"
class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<timestamp>
<timeZone>UTC</timeZone>
</timestamp>
<pattern>
<pattern>
{
"logLevel": "%level",
"serviceName": "${springAppName:-}",
"pid": "${PID:-}",
"thread": "%thread",
"class": "%logger{40}",
"rest": "%message"
}
</pattern>
</pattern>
</providers>
</encoder>
</appender>
<root level="INFO">
<appender-ref ref="LOGSTASH" />
<appender-ref ref="CONSOLE" />
</root>
</configuration>
複製代碼
在logstash 配置文件logstash.conf 增長日誌收集配置信息bash
# Sample Logstash configuration for creating a simple
# Beats -> Logstash -> Elasticsearch pipeline.
input {
tcp {
mode => "server"
host => "192.168.92.50"
port => 4560
codec => json_lines
}
}
output {
elasticsearch {
hosts => "192.168.92.50:9200"
index => "springboot-logstash-%{+YYYY.MM.dd}"
}
}
複製代碼
注意上述配置的host地址和es地址信息,利用這次配置文件啓動logstash服務。app
啓動springboot服務, 在kibana配置日誌攔截器 elasticsearch
輸入咱們logstash日誌配置的名稱 繼續下一步,選擇帶時間戳過濾器 點擊左側Discover菜單,已經發現數據已經展示