如何通过fluentd插件将字段插入日志

时间:2019-09-29 06:57:52

标签: fluentd

我正在配置流利的将日志转发到ELK服务器,并且想在日志记录中插入一些字段,如何实现呢?

我知道有一个名为“ record_transformer”的插件,我可以插入简单的key:value格式,但是我想插入一些带有uuid,日志文件路径等的json块。

例如,在日志消息之前

{
  "app": "default",
  "logger": "org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor",
  "level": "INFO",
  "class": "org.springframework.scheduling.concurrent.ExecutorConfigurationSupport",
  "method": "shutdown",
  "file": "ExecutorConfigurationSupport.java",
  "line": 208,
  "thread": "Thread-7",
  "message": "Shutting down ExecutorService"
}

我想在json下方插入日志,应该生成uuid并且该uuid是唯一的,偏移量应该是日志文件位置的行号

{
"agent": {
"id": "{uuid}"
},
"log": {
"file": {
"path": "/path/to/log/file"
},
"offset": <log file line number>
}
}

最终输出应为:

{
  "app": "default",
  "logger": "org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor",
  "level": "INFO",
  "class": "org.springframework.scheduling.concurrent.ExecutorConfigurationSupport",
  "method": "shutdown",
  "file": "ExecutorConfigurationSupport.java",
  "line": 208,
  "thread": "Thread-7",
  "message": "Shutting down ExecutorService",
  "agent": {
    "id": "{uuid}"
  },
  "log": {
    "file": {
      "path": "/path/to/log/file"
    },
    "offset": <log file line number>
  }
}

0 个答案:

没有答案