項目中我們常用的是把Logback打印的日志存儲到文件中保存到硬盤上,這樣不利於日志的收集和分析。
以下演示在SpringBoot中通過rabbitmq收集logback日志存儲到Elasticsearch中。
環境准備:安裝RabbitMQ,安裝Elasticsearch和Elasticsearch-Head(可視化插件),安裝Logstash.====》之前博客已經介紹過了。
pom.xml
引入spring-amqp
logback-spring.xml
Logstash配置
在logstash安裝目錄的bin目錄下新建
logstash-rabbitmq.conf ====>從消息隊列讀日志
配置如下,logstash整合rabbitmq詳細配置見https://www.elastic.co/guide/en/logstash/current/plugins-inputs-rabbitmq.html
額外:從文件目錄讀日志
以上配置完成,啟動rabbitmq,logstash(logstash -f logstash-rabbitmq.conf),elasticsearch,elasticsearch-head,springboot項目。
控制台一直在打印日志
rabbitmq消息狀態
后期也可以整合Kinbana
微信公眾號