elasticsearch+ kibana+ logstash+ filebeat构建高可用分布式日志集群系统(三):springboot微服务的日志整合

elk 提供了完备且成熟的日志存储和分析的解决方案,本文主要介绍 springboot微服务与elk的日志整合

在上篇文章中介绍了kibana + logstash+ filebea集群的安装,本文章为大家介绍如何实现springboot微服务与elk的日志整合。 

elasticsearch+ kibana+ logstash+ filebeat构建高可用分布式日志集群系统(二):kibana + logstash+ filebea集群的安装

elasticsearch+ kibana+ logstash+ filebeat构建高可用分布式日志集群系统(三):springboot微服务的日志整合(本文)

1.新建account/product/insurance服务,并在pom引入

        
            net.logstash.logback
            logstash-logback-encoder
            5.3
        

2.account在resources下添加logback-spring.xml   修改相关配置如下




    
    
    
    
    
    
    
    
    
        
            INFO
        
        
        
            ${CONSOLE_LOG_PATTERN}
            utf8
        
    
    
    
        
            
            logs/${service_Name}-info-%d{yyyy-MM-dd}-%i.log
            
            100MB
            30
            20GB
        
        
        
            ${CONSOLE_LOG_PATTERN}
            utf8
        
    
    
    
        
            ERROR
        
        
            
            logs/${service_Name}-error-%d{yyyy-MM-dd}-%i.log
            
            100MB
            30
            20GB
        
        
        
            ${CONSOLE_LOG_PATTERN}
            utf8
        
    
    
    
        
        192.168.77.120:45001,192.168.77.130:45001,192.168.77.140:45001
        
            
                5 minutes
            
        
        
        1 second
        
        16384
        
        
            
                
                    UTC
                
                
                    
                        {
                        "span": "%X{X-B3-SpanId:-}",
                        "exportable": "%X{X-Span-Export:-}",
                        "pid": "${PID:-}",
                        "springHost": "%ip",
                        "rest": "%message",
                        "thread": "%thread",
                        "severity": "%level",
                        "class": "%logger{40}",
                        "service": "${springAppName:-}"
                        }
                    
                
            
        
    
    
    
        
        
        
        
    

3.product服务在resources下添加logback-spring.xml   修改相关配置如下




    
    
    
    
    
    
    
    
    
        
            INFO
        
        
        
            ${CONSOLE_LOG_PATTERN}
            utf8
        
    
    
    
        
            
            logs/${service_Name}-info-%d{yyyy-MM-dd}-%i.log
            
            100MB
            30
            20GB
        
        
        
            ${CONSOLE_LOG_PATTERN}
            utf8
        
    
    
    
        
            ERROR
        
        
            
            logs/${service_Name}-error-%d{yyyy-MM-dd}-%i.log
            
            100MB
            30
            20GB
        
        
        
            ${CONSOLE_LOG_PATTERN}
            utf8
        
    
    
    
        
        192.168.77.120:45002,192.168.77.130:45002,192.168.77.140:45002
        
            
                5 minutes
            
        
        
        1 second
        
        16384
        
        
            
                
                    UTC
                
                
                    
                        {
                        "span": "%X{X-B3-SpanId:-}",
                        "exportable": "%X{X-Span-Export:-}",
                        "pid": "${PID:-}",
                        "springHost": "%ip",
                        "rest": "%message",
                        "thread": "%thread",
                        "severity": "%level",
                        "class": "%logger{40}",
                        "service": "${springAppName:-}"
                        }
                    
                
            
        
    
    
    
        
        
        
        
    

4.insurance服务在resources下添加logback-spring.xml   修改相关配置如下




    
    
    
    
    
    
    
    
    
        
            INFO
        
        
        
            ${CONSOLE_LOG_PATTERN}
            utf8
        
    
    
    
        
            
            logs/${service_Name}-info-%d{yyyy-MM-dd}-%i.log
            
            100MB
            30
            20GB
        
        
        
            ${CONSOLE_LOG_PATTERN}
            utf8
        
    
    
    
        
            ERROR
        
        
            
            logs/${service_Name}-error-%d{yyyy-MM-dd}-%i.log
            
            100MB
            30
            20GB
        
        
        
            ${CONSOLE_LOG_PATTERN}
            utf8
        
    
    
    
        
        
192.168.77.120:45003,192.168.77.130:45003,192.168.77.140:45003
        
            
                5 minutes
            
        
        
        1 second
        
        16384
        
        
            
                
                    UTC
                
                
                    
                        {
                        "span": "%X{X-B3-SpanId:-}",
                        "exportable": "%X{X-Span-Export:-}",
                        "pid": "${PID:-}",
                        "springHost": "%ip",
                        "rest": "%message",
                        "thread": "%thread",
                        "severity": "%level",
                        "class": "%logger{40}",
                        "service": "${springAppName:-}"
                        }
                    
                
            
        
    
    
    
        
        
        
        
    

 

 

你可能感兴趣的:(Linux相关,java相关)