首页 > 解决方案 > Cloudwatch 日志配置:timestamp_format 匹配

问题描述

我错过了AWS 文档中描述如何在给定行内评估 timestamp_format 的部分。

这里我有一个示例日志行:

[4138] 2021/07/19 15:20:57.996872 [INF] Listening for client connections on ...

如您所见,日期时间信息位于第二列。Cloudwatch 是否会自动匹配整行中配置的 timestamp_format 模式,还是始终假定 datetime 列需要位于第一列?我如何告诉 Cloudwatch 代理使用第二列进行timestamp_format匹配?

标签: loggingamazon-cloudwatch

解决方案


根据经验,它会找到第一个匹配的时间戳timestamp_format。从我读过的文档来看,有点模棱两可。文档中有两个声明似乎证实了这一说法。

timestamp_format项目符号下有声明:

If a single log entry contains two time stamps that match the format, the first time stamp is used.

这表明它正在查看整个日志条目以查找匹配项,而不仅仅是解析第一个日期字段。

multi_line_start_pattern项目符号下有声明:

If you include this field, you can specify {timestamp_format} to use the same regular expression as your timestamp format. Otherwise, you can specify a different regular expression for CloudWatch Logs to use to determine the start lines of multi-line entries.

这表明我再次timestamp_format习惯于在整个日志条目中进行模式匹配。


推荐阅读