正则加速

简介

processor_regex_accelerate processor插件通过正则匹配以加速模式实现文本日志的字段提取。

备注:该插件目前仅支持与输入插件file_log和输出插件flusher_sls配套使用,且不得与其它加速插件混用。

版本

Stable

配置参数

  • 表1:时间格式

  • 表2:脱敏信息

样例

单行日志采集

采集/home/test-log/路径下的reg.log文件,日志内容按照提取字段。

  • 输入

127.0.0.1 - - [07/Jul/2022:10:43:30 +0800] "POST /PutData?Category=YunOsAccountOpLog" 0.024 18204 200 37 "-" "aliyun-sdk-java"' >> /home/test-log/reg.log

  • 采集配置

enable: true
inputs:
  - Type: file_log
    LogPath: /home/test-log/
    FilePattern: reg.log
processors:
  - Type: processor_regex_accelerate
    Keys:
    - ip
    - time
    - method
    - url
    - request_time
    - request_length
    - status
    - length
    - ref_url
    - browser
    Regex: ([\d\.]+) \S+ \S+ \[(\S+) \S+\] \"(\w+) ([^\\"]*)\" ([\d\.]+) (\d+) (\d+) (\d+|-) \"([^\\"]*)\" \"([^\\"]*)\"
flushers:
  - Type: flusher_sls
    Endpoint: cn-xxx.log.aliyuncs.com
    ProjectName: test_project
    LogstoreName: test_logstore
  • 输出

{
    "__tag__:__path__": "/home/test-log/reg.log",
    "ip": "127.0.0.1",
    "time": "07/Jul/2022:10:43:30",
    "method": "POST",
    "url": "/PutData?Category=YunOsAccountOpLog",
    "request_time": "0.024",
    "request_length": "18204",
    "status": "200",
    "length": "37",
    "ref_url": "-",
    "browser": "aliyun-sdk-java",
    "__time__": "1657161810"
}

多行日志采集

采集/home/test-log/路径下的regMulti.log文件,日志内容按照提取字段。

  • 输入

[2022-07-07T10:43:27.360266763] [INFO] java.lang.Exception: exception happened
    at com.aliyun.sls.devops.logGenerator.type.RegexMultiLog.f2(RegexMultiLog.java:108)
    at java.base/java.lang.Thread.run(Thread.java:833)
  • 采集配置

enable: true
inputs:
  - Type: file_log
    LogPath: /home/test-log/
    FilePattern: regMulti.log
processors:
  - Type: processor_regex_accelerate
    Keys:
    - time
    - level
    - msg
    Regex: \[(\S+)]\s\[(\S+)]\s(.*)
    LogBeginRegex: \[\d+-\d+-\w+:\d+:\d+,\d+]\s\[\w+]\s.*
flushers:
  - Type: flusher_sls
    Endpoint: cn-xxx.log.aliyuncs.com
    ProjectName: test_project
    LogstoreName: test_logstore
  • 输出

{
    "__tag__:__path__": "/home/test-log/regMulti.log",
    "time": "2022-07-07T10:43:27.360266763",
    "level": "INFO",
    "msg": "java.lang.Exception: exception happened
    at com.aliyun.sls.devops.logGenerator.type.RegexMultiLog.f2(RegexMultiLog.java:108)
    at java.base/java.lang.Thread.run(Thread.java:833)",
    "__time__": "1657161807"
}

Last updated