1、下载 ES
https://www.elastic.co/cn/dow…
2、启动 ES
3、查看 http://localhost:9200/
4、下载 logstash
https://www.elastic.co/cn/dow…
5、装置 logstatsh
5.1 配置 logstash
input {
tcp {
port => "5044"
codec => json
}
}
output {
elasticsearch {hosts => ["localhost:9200"]
index => "document"
}
stdout {codec => rubydebug}
}
启动 logstash
D:\logstash-7.12.0\bin>logstash.bat -f ../config/logstash.conf
装置 logstash 插件
D:\logstash-7.12.0\bin>logstash-plugin install 插件名
6、下载 kibana
https://www.elastic.co/cn/dow…
装置 kibana,配置文件在 config 目录下
启动 kibana
7、logback.xml 配置
maven 依赖
<dependency>
<groupId>net.logstash.logback</groupId>
<artifactId>logstash-logback-encoder</artifactId>
<version>4.9</version>
</dependency>
logback.xml 配置
<configuration>
<springProperty name="LOG_PATH" source="logging.path" defaultValue="/usr/data/applicationName" />
<appender name="LOGSTASH" class="net.logstash.logback.appender.LogstashTcpSocketAppender">
<destination>127.0.0.1:5044</destination>
<!-- <encoder charset="UTF-8" class="net.logstash.logback.encoder.LogstashEncoder" /> -->
<!-- 日志输入编码 -->
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<timestamp>
<timeZone>UTC</timeZone>
</timestamp>
<pattern>
<pattern>
{
"severity": "%level",
"service": "applicationName",
"thread": "%thread",
"class": "%logger{40}",
"msg": "%message"
}
</pattern>
</pattern>
</providers>
</encoder>
</appender>
<root level="ERROR">
<appender-ref ref="LOGSTASH" />
</root>
</configuration>
注意事项,装置目录最好不要有中文字符