logstash通过grok插件匹配springBoot默认日志

背景:在 Logstash数据源为日志文件操作 基础上进行

一、修改配置

1. logstash.conf文件修改为如下

input { 
    stdin { } 
    file {
        # 容器中日志所在目录的文件
        path => ["/usr/share/logstash/logs/*.log"]
        # 多行匹配方法1
        codec => multiline {
            pattern => "^(%{TIMESTAMP_ISO8601})"
            negate => true
            what => "previous"
        }
        sincedb_path => "NUL"
        type => "spring"
        start_position => "beginning"
    }
}

filter {
    if [type] == "spring" {
        # 多行匹配方法2
       # multiline {
            # pattern => "^(%{TIMESTAMP_ISO8601})"
            # negate => true
            # what => "previous"
       # }
        grok {
            # Do multiline matching with (?m) as the above mutliline filter may add newlines to the log messages.
            match => [ "message", "(?m)^%{TIMESTAMP_ISO8601:timestamp}%{SPACE}%{LOGLEVEL:logLevel}%{SPACE}%{NUMBER:pid}%{SPACE}---%{SPACE}%{SYSLOG5424SD:threadName}%{SPACE}%{NOTSPACE:loggerName}%{SPACE}:%{SPACE}%{GREEDYDATA:message}" ]
            # 覆盖原有的message
            overwrite=> [ "message" ]
        }
   }
}


output {
    if [type] == "spring" {
        elasticsearch {
            hosts => ["es:9200"]
            index => "spring-%{+YYYY.MM.dd}"
        }
    }
	stdout { codec => rubydebug }
}

二、模拟日志

1. D:\usr\local\logs目录下添加日志文件spring-2020-05-25.log,内容如下

2020-05-15 17:54:50.805 DEBUG 8296 --- [scheduling-1] org.jooq.tools.LoggerListener            : Executing query          : select id from user
2020-05-15 17:54:52.945 DEBUG 1012 --- [scheduling-1] org.jooq.tools.LoggerListener            : Executing query          : select id from user
2020-05-21 19:55:52.945 DEBUG 1012 --- [scheduling-1] org.jooq.tools.LoggerListener            : Executing query         
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值