【问题标题】:fluentd parsing syslog and get content onlyfluentd解析系统日志并仅获取内容
【发布时间】:2021-11-18 13:39:43
【问题描述】:

我使用 google-fluentd 将日志发送到 GCP。问题是 GCP 日志记录需要将日志作为结构化日志,即 JSON 日志。我的服务已经将日志打印为结构化日志,但它具有时间戳、主机名和服务名称等前缀,这些前缀变成了非结构化日志。那么,如何将如下所示的 syslog 解析为结构化日志,但只解析没有前缀的内容?

之前:

Nov 18 19:33:00 hostname-one service-name[909622]: {"timestamp":"2021-11-18T19:33:00.899671988+07:00","correlationId":"52e74b0d-bf41-4e41-ba8d-edc9f7062726","method":"POST","url":"/my/url","status":200,"responseTime":0.052602809}

之后/预期:

{"timestamp":"2021-11-18T19:33:00.899671988+07:00","correlationId":"52e74b0d-bf41-4e41-ba8d-edc9f7062726","method":"POST","url":"/my/url","status":200,"responseTime":0.052602809}

【问题讨论】:

    标签: logging google-cloud-platform fluentd


    【解决方案1】:

    您可以通过将其添加到 fluentd 配置文件中来更改格式以清除 json:

    <format>
      @type json
    </format>
    

    在 fluentd documentation 中有更多关于配置输出的信息。

    【讨论】:

    • 请看我的日志内容。 @type json 仅可用于完全记录 json。我的日志包含前缀时间戳。
    猜你喜欢
    • 2021-10-29
    • 2017-05-18
    • 2022-08-22
    • 2020-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 2018-06-19
    相关资源
    最近更新 更多