1

我想将 kubernetes 日志输出到文件中。但是,我只能将其输出为 json 数据。我只想将“消息”部分输出到文件。

如何选择“消息”进行打印?我应该选择哪种过滤器?

<match output_tag>
  @type rewrite_tag_filter
  <rule>
    key $['kubernetes']['labels']['app']
    pattern ^(.+)$
    tag app.$1
  </rule>
</match>
<match app.tom1>
  @type file
  path /logs/tom1
</match>



Execute result:--->

2019-10-30T00:46:05+09:00   app.tom1    {
..
  "message": "2019-10-29 15:46:05,253 DEBUG [org.springframework.web.servlet.DispatcherServlet] Successfully completed request",
  "kubernetes": {
    "labels": {
      "app": "tom1",
..
}


Desired result: --->
2019-10-29 15:46:05,253 DEBUG [org.springframework.web.servlet.DispatcherServlet] Successfully completed request

感谢!

4

1 回答 1

2

试试single_value <formater>插件:https ://docs.fluentd.org/formatter/single_value

<match app.tom1>
  @type file
  path /logs/tom1
  <format>
    @type single_value
    message_key message
  </format>
</match>
于 2019-10-29T18:18:22.437 回答