当前位置:   article > 正文

springboot 发送logback日志到elk_spring boot logback日志推送到vue

spring boot logback日志推送到vue

1.     引入依赖

<dependency>
  
<groupId>net.logstash.logback</groupId>
  
<artifactId>logstash-logback-encoder</artifactId>
  
<version>4.11</version>
</dependency>

 

2.     日志配置

在logback.xml文件添加如下配置:

  1. <appender name="LOGSTASH"
  2.        class="net.logstash.logback.appender.LogstashTcpSocketAppender">
  3.    <destination>xx.xx.xx.xx:5044</destination>
  4.    <!-- encoder必须配置,有多种可选 -->
  5.    <encoder charset="UTF-8"
  6.           class="net.logstash.logback.encoder.LogstashEncoder" >
  7.       <!-- "logName":"comba-community" 的作用是指定创建索引的名字时用,并且在生成的文档中会多了这个字段  -->
  8.       <customFields>{"logName":"comba-community"}</customFields>
  9.    </encoder>
  10.    <filter class="ch.qos.logback.classic.filter.LevelFilter">
  11.       <level>INFO</level>
  12.    </filter>
  13. </appender>

 

  1. <!-- additivity 避免执行2次 -->
  2. <logger name="com.comba.controller" level="INFO" additivity="false">
  3.    <appender-ref ref="STDOUT" />
  4.    <appender-ref ref="INFO_FILE" />
  5.    <appender-ref ref="ERROR_FILE" />
  6.    <appender-ref ref="DEBUG_FILE" />
  7.    <appender-ref ref="LOGSTASH" />
  8. </logger>
  9. <root level="${root.level}">
  10.    <appender-ref ref="STDOUT" />
  11.    <appender-ref ref="INFO_FILE" />
  12.    <appender-ref ref="ERROR_FILE" />
  13.    <appender-ref ref="DEBUG_FILE" />
  14.    <appender-ref ref="LOGSTASH" />
  15. </root>

有多个logstash IP添加如下配置:

<connectionStrategy>
<roundRobin>
<connectionTTL>5minutes</connectionTTL>
</roundRobin>
</connectionStrategy>

这个配置是向logstash输出日志如果有多个logstash IP或端口可以轮询负载各端口

3.     Logstash配置

  1. input {
  2.     tcp {
  3.         port => 5044
  4.         mode => "server"
  5.         tags => ["tags"]
  6.         codec => json_lines
  7.     }
  8. }
  9. output {
  10.   elasticsearch {
  11.     hosts => "192.168.2.210:9200"
  12.     index => "%{[logName]}-%{+YYYY.MM.dd}"
  13.     user => "elastic"
  14.     password => "changeme"
  15.   }
  1. #控制台输出日志
  2.   #stdout {codec => rubydebug }
  3. }

服务器logstash控制输出的日志:

 

4.     参考链接

https://blog.csdn.net/yy756127197/article/details/78873310

https://blog.csdn.net/u014527058/article/details/70495595

 

 logstash-logback-encoder源码:

https://github.com/logstash/logstash-logback-encoder

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/天景科技苑/article/detail/764634
推荐阅读
相关标签
  

闽ICP备14008679号