alibaba / ilogtail

Fast and Lightweight Observability Data Collector
https://ilogtail.gitbook.io/ilogtail-docs
Apache License 2.0
1.71k stars 384 forks source link

[backport 1.8] Add processor_gotime with nanosecond to other time format conversion capability #1672

Closed quzard closed 1 month ago

quzard commented 1 month ago

作用:支持将日志里的纳秒时间转换成其他时间格式

日志样例:time:1645595256807000123 插件配置样例:

enable: true
global:
  EnableTimestampNanosecond: true
inputs:
  - Type: input_file
    FilePaths: 
      - /workspaces/ilogtail_version2/bin/ilogtail/test.log
processors:
  - Type: processor_regex
    FullMatch: false
    KeepSource: true
    KeepSourceIfParseError: true
    Keys:
    - time
    NoKeyError: true
    NoMatchError: true
    Regex: time:(.*)
    SourceKey: content
  - Type: processor_gotime
    AlarmIfFail: true
    DestFormat: '2006-01-02 15:04:05.000000000'
    DestKey: timeNano
    DestLocation: 8
    KeepSource: true
    NoKeyError: true
    SetTime: true
    SourceFormat: nanoseconds
    SourceKey: time
    SourceLocation: 8
flushers:
  - Type: flusher_stdout
    OnlyStdout: true

日志输出结果

{"content":"time:1645595256807000123","time":"1645595256807000123","timeNano":"2022-02-23 13:47:36.807000123","__time__":"1645595256"}