将多行JSON日志上传到AWS CloudWatch Log

问题描述 投票:0回答:1

[put-log-events期望JSON文件需要由[]换行

例如

# aws logs put-log-events --log-group-name my-logs --log-stream-name 20150601 --log-events file://events

[
  {
    "timestamp": long,
    "message": "string"
  }
  ...
]

但是,我的JSON文件是多行格式,例如

{"timestamp": xxx, "message": "xxx"}
{"timestamp": yyy, "message": "yyy"}

是否可以在不编写自己的程序的情况下上传?

[1] https://docs.aws.amazon.com/cli/latest/reference/logs/put-log-events.html#examples

amazon-web-services amazon-cloudwatch amazon-cloudwatchlogs
1个回答
0
投票

如果要将这些行保留为单个事件,则可以将这些行强制转换为字符串,将其与\n合并并以这种方式发送。

由于行本身看起来像是自给自足的json,所以将它们作为事件数组发送(因此[...])可能并没有那么糟糕,因为它们将进入同一日志组,并且很容易成批查找。

© www.soinside.com 2019 - 2024. All rights reserved.