normalize

(该interceptor后续不再维护,建议使用transformer替换)

用于日志切分处理。
属于source interceptor。可指定只被某些source使用。

processors

字段类型是否必填默认值含义
processors数组必填所有的处理processor列表

配置的processor将按照顺序依次执行。

Tips

Loggie支持使用a.b的形式引用嵌套的字段。 比如数据为:

  1. {
  2. "fields": {
  3. "hello": "world"
  4. }
  5. }

下面的processor配置中均可以使用fields.hello指定嵌套在fields里的hello: world

addMeta

默认情况下,Loggie不会添加任何的系统内部信息到原始数据中。
可通过addMeta添加系统内置字段发送给下游。

Note

请注意,在pipeline中配置addMeta,只会影响该pipeline发送的所有数据,如果需要全局生效,请在defaults中配置normalize.addMeta。

  1. loggie:
  2. defaults:
  3. interceptors:
  4. - type: normalize
  5. name: global
  6. processors:
  7. - addMeta: ~
字段类型是否必填默认值含义
targetstring非必填meta系统内置字段添加到event中的字段名

regex

将指定字段进行正则提取。

字段类型是否必填默认值含义
regex.patternstring必填正则解析规则
regex.targetstring非必填body正则解析的目标字段
regex.ignoreErrorbool非必填false是否忽略错误

Example

  1. interceptors:
  2. - type: normalize
  3. processors:
  4. - regex:
  5. pattern: '(?<ip>\S+) (?<id>\S+) (?<u>\S+) (?<time>\[.*?\]) (?<url>\".*?\") (?<status>\S+) (?<size>\S+)'

使用以上的正则表达式,可以将以下示例的日志:

  1. 10.244.0.1 - - [13/Dec/2021:12:40:48 +0000] "GET / HTTP/1.1" 404 683

转换成:

  1. "ip": "10.244.0.1",
  2. "id": "-",
  3. "u": "-",
  4. "time": "[13/Dec/2021:12:40:48 +0000]",
  5. "url": "\"GET / HTTP/1.1\"",
  6. "status": "404",
  7. "size": "683"

具体配置的时候,建议先使用一些正则调试工具 (https://regex101.com/) 验证是否可以匹配。

jsonDecode

将指定字段json解析提取。

字段类型是否必填默认值含义
jsonDecode.targetstring非必填bodyjson decode的目标字段
jsonDecode.ignoreErrorbool非必填false是否忽略错误

Example

  1. interceptors:
  2. - type: normalize
  3. processors:
  4. - jsonDecode: ~

split

将指定字段通过分隔符进行提取。

字段类型是否必填默认值含义
split.targetstring非必填bodysplit的目标字段
split.separatorstring必填分隔符
split.maxint非必填-1通过分割符分割后得到的最多的字段数
split.keysstring数组必填分割后字段对应的key
split.ignoreErrorbool非必填false是否忽略错误

Example

base

  1. interceptors:
  2. - type: normalize
  3. processors:
  4. - split:
  5. separator: '|'
  6. keys: ["time", "order", "service", "price"]

使用以上split配置可以将日志:

  1. 2021-08-08|U12345|storeCenter|13.14

转换成:

  1. "time": "2021-08-08"
  2. "order": "U12345"
  3. "service": "storeCenter"
  4. "price": 13.14

max

  1. interceptors:
  2. - type: normalize
  3. processors:
  4. - split:
  5. separator: ' '
  6. max: 2
  7. keys: ["time", "content"]

通过增加max参数,可以控制最多分割的字段。
比如以下日志:

  1. 2021-08-08 U12345 storeCenter 13.14

可以通过以上配置提取为:

  1. "time": "2021-08-08"
  2. "content": "U12345 storeCenter 13.14"

drop

丢弃指定字段。

字段类型是否必填默认值含义
drop.targetsstring数组必填drop的字段

Example

  1. interceptors:
  2. - type: normalize
  3. processors:
  4. - drop:
  5. targets: ["id", "body"]

rename

重命名指定字段。

字段类型是否必填默认值含义
rename.convert数组必填
rename.convert[n].fromstring必填rename的目标
rename.convert[n].tostring必填rename后的名称

Example

  1. interceptors:
  2. - type: normalize
  3. processors:
  4. - rename:
  5. convert:
  6. - from: "hello"
  7. to: "world"

add

新增字段。

字段类型是否必填默认值含义
add.fieldsmap必填新增的key:value值

Example

  1. interceptors:
  2. - type: normalize
  3. processors:
  4. - add:
  5. fields:
  6. hello: world

convert

字段类型转换。

字段类型是否必填默认值含义
convert.convert数组必填
convert.convert[n].fromstring必填需要转换的字段名
convert.convert[n].tostring必填转换后的类型,可为:”bool”, “integer”, “float”

Example

  1. interceptors:
  2. - type: normalize
  3. processors:
  4. - convert:
  5. convert:
  6. - from: count
  7. to: float

copy

字段复制。

字段类型是否必填默认值含义
copy.convert数组必填
copy.convert[n].fromstring必填需要复制的字段名
copy.convert[n].tostring必填复制后的字段名

Example

  1. interceptors:
  2. - type: normalize
  3. processors:
  4. - copy:
  5. convert:
  6. - from: hello
  7. to: world

underRoot

将字段中的所有key:value放到event最外层。

字段类型是否必填默认值含义
underRoot.keysstring数组必填需要underRoot的字段名

Example

  1. interceptors:
  2. - type: normalize
  3. processors:
  4. - underRoot:
  5. keys: ["fields"]

timestamp

转换时间格式。

字段类型是否必填默认值含义
timestamp.convert数组必填
timestamp.convert[n].fromstring必填指定转换时间格式的字段
timestamp.convert[n].fromLayoutstring必填指定字段的时间格式(golang形式)
timestamp.convert[n].toLayoutstring必填转换后的时间格式(golang形式),另外可为unixunix_ms
timestamp.convert[n].toTypestring非必填转换后的时间字段类型
timestamp.convert[n].localbool非必填false是否将解析的时间转成当前时区

Example

  1. interceptors:
  2. - type: normalize
  3. processors:
  4. - timestamp:
  5. convert:
  6. - from: logtime
  7. fromLayout: "2006-01-02T15:04:05Z07:00"
  8. toLayout: "unix"

以上的layout参数需要填写golang形式,可参考:

  1. const (
  2. Layout = "01/02 03:04:05PM '06 -0700" // The reference time, in numerical order.
  3. ANSIC = "Mon Jan _2 15:04:05 2006"
  4. UnixDate = "Mon Jan _2 15:04:05 MST 2006"
  5. RubyDate = "Mon Jan 02 15:04:05 -0700 2006"
  6. RFC822 = "02 Jan 06 15:04 MST"
  7. RFC822Z = "02 Jan 06 15:04 -0700" // RFC822 with numeric zone
  8. RFC850 = "Monday, 02-Jan-06 15:04:05 MST"
  9. RFC1123 = "Mon, 02 Jan 2006 15:04:05 MST"
  10. RFC1123Z = "Mon, 02 Jan 2006 15:04:05 -0700" // RFC1123 with numeric zone
  11. RFC3339 = "2006-01-02T15:04:05Z07:00"
  12. RFC3339Nano = "2006-01-02T15:04:05.999999999Z07:00"
  13. Kitchen = "3:04PM"
  14. // Handy time stamps.
  15. Stamp = "Jan _2 15:04:05"
  16. StampMilli = "Jan _2 15:04:05.000"
  17. StampMicro = "Jan _2 15:04:05.000000"
  18. StampNano = "Jan _2 15:04:05.000000000"
  19. )

还可以根据实际情况修改。

fmt

字段内容重新格式化。可根据其他字段内容进行组合和格式化。

字段类型是否必填默认值含义
fmt.fieldsmap必填key表示需要格式化的字段名称,value为需要格式化的内容。可使用${}的方式表示取值某个字段

Example

  1. interceptors:
  2. - type: normalize
  3. processors:
  4. - fmt:
  5. fields:
  6. d: new-${a.b}-${c}