本篇文章給大家分享的是有關(guān)怎樣實(shí)現(xiàn)springboot向elk寫(xiě)日志,小編覺(jué)得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說(shuō),跟著小編一起來(lái)看看吧。
springboot里連接elk里的logstash,然后寫(xiě)指定index索引的日志,而之后使用kibana去查詢(xún)和分析日志,使用elasticsearch去保存日志。
添加引用
implementation 'net.logstash.logback:logstash-logback-encoder:5.3'
添加配置
指定配置
server.port=81logging.config=classpath:logback-spring.xml
logstash配置索引
input { tcp { port => 5000 codec => "json" }}## Add your filters / logstash plugins configuration hereoutput { elasticsearch { hosts => "elasticsearch:9200" user => "elastic" password => "changeme" index => "%{[appname]}" }}
kibana里建立索引
通過(guò)kiban菜單去建立索引:Management>Index patterns>Create index pattern,這里會(huì)顯示可用的索引名稱(chēng)。
以上就是怎樣實(shí)現(xiàn)springboot向elk寫(xiě)日志,小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見(jiàn)到或用到的。希望你能通過(guò)這篇文章學(xué)到更多知識(shí)。更多詳情敬請(qǐng)關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。