AWS 云监视日志格式

问题描述

我对 Cloud Watch 上的日志有疑问。 我一直将日志记录在不​​同的条目上,而不是每个日志只有一个条目。这是一个例子。

控制台输出

[2020-12-21T11:51:21.966] [ERROR] default - [handlerProcess] [
  ValidationError {
    target: OnbroadcastStart {
      broadcast_id: 'bro_...',session_id: null,timestamp: '2020-12-21T11:51:21.920Z'
    },value: null,property: 'session_id',children: [],constraints: {
      isNotEmpty: 'session_id should not be empty',isstring: 'session_id must be a string'
    }
  }
]

This is the output from a single error log.

云表输出

[2020-12-21T11:51:21.966] [ERROR] default - [handlerProcess] [
[2020-12-21T11:51:21.966]   ValidationError {
[2020-12-21T11:51:21.966]     target: OnbroadcastStart {
[2020-12-21T11:51:21.966]       broadcast_id: 'bro_...',[2020-12-21T11:51:21.966]       session_id: null,[2020-12-21T11:51:21.966]       timestamp: '2020-12-21T11:51:21.920Z'
[2020-12-21T11:51:21.966]     },[2020-12-21T11:51:21.966]     value: null,[2020-12-21T11:51:21.966]     property: 'session_id',[2020-12-21T11:51:21.966]     children: [],[2020-12-21T11:51:21.966]     constraints: {
[2020-12-21T11:51:21.966]       isNotEmpty: 'session_id should not be empty',[2020-12-21T11:51:21.966]       isstring: 'session_id must be a string'
[2020-12-21T11:51:21.966]     }
[2020-12-21T11:51:21.966]   }
[2020-12-21T11:51:21.966] ]

这里的每一行都是一个条目。

有什么办法可以解决这个问题吗?作为项目的记录器,我使用的是 Log4js。

解决方法

因此,如果您使用的是 Cloudwatch 代理,则需要调整 Timestamp_format 设置。如果您不指定格式,CloudWatch 将使用特定于时代的时间戳和日期 ping 日志的每一行。

要调整代理设置,您可以在此处找到信息: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch-Agent-Configuration-File-Details.html