schema

Used to convert log format.
Source interceptor.

Use Cases

For some log scenarios, there may be some differences in the log format we require. These differences are mainly in the time field, body field, and so on. By default, Loggie will only put the raw data collected or received by the source into the body field and send it in the simplest way:

  1. {
  2. "body": "this is raw data"
  3. }

But, sometimes, we need to:

  • add time field
  • modify body and other fields

Example

add @timestamp, modify body to message

  1. interceptors:
  2. - type: schema
  3. addMeta:
  4. timestamp:
  5. key: "@timestamp"
  6. remap:
  7. body:
  8. key: message

event converted:

  1. {
  2. "message": "this is raw data"
  3. "@timestamp": "2022-08-30T06:58:49.545Z",
  4. }

add timestamp,modify timezone and format, modift body to log

  1. interceptors:
  2. - type: schema
  3. addMeta:
  4. timestamp:
  5. key: "_timestamp_"
  6. location: Local
  7. layout: 2006-01-02T15:04:05Z07:00
  8. remap:
  9. body:
  10. key: _log_

Configuration

addMeta

fieldtyperequireddefaultdescription
addMetafalseadd meta info

timestamp

fieldtyperequireddefaultdescription
addMeta.timestampfalseadd time field(time when log is collected)
addMeta.timestamp.keystringtruekey for system time
addMeta.timestamp.locationstringfalseUTCadd time zone. Local supported
addMeta.timestamp.layoutstringfalse“2006-01-02T15:04:05.000Z”golang time format layout, refer to https://go.dev/src/time/format.go

pipelineName

fieldtyperequireddefaultdescription
addMeta.pipelineNamefalseadd pipelineName into event
addMeta.pipelineName.keystringtruefield key for pipelineName

Example

  1. interceptors:
  2. - type: schema
  3. addMeta:
  4. pipelineName:
  5. key: pipeline

event converted:

  1. {
  2. "pipeline": "demo"
  3. ...
  4. }

sourceName

fieldtyperequireddefaultdescription
addMeta.sourceNamefalseadd sourceName into event
addMeta.sourceName.keystringtruefield key for sourceName

Example

  1. interceptors:
  2. - type: schema
  3. addMeta:
  4. sourceName:
  5. key: source

event converted:

  1. {
  2. "source": "local"
  3. ...
  4. }

remap

fieldtyperequireddefaultdescription
remapmapfalseconvert field. rename supported currently.
remap.[originKey]stringfalseoriginal key
remap.[originKey].keystringfalseconverted key

Example

  1. interceptors:
  2. - type: schema
  3. remap:
  4. body:
  5. key: msg
  6. state:
  7. key: meta

original event:

  1. {
  2. "body": "this is log"
  3. "state": "ok",
  4. }

event converted:

  1. {
  2. "msg": "this is log"
  3. "meta": "ok",
  4. }