【问题标题】:Is it possible to display n messages prior to a message that matches regex using aws cloud watch logs insights是否可以使用 aws cloud watch logs 洞察在匹配正则表达式的消息之前显示 n 条消息
【发布时间】:2025-11-30 06:25:02
【问题描述】:

是否可以使用 aws 云观察日志洞察在匹配正则表达式的消息之前显示 n 条消息。 我必须对多个日志事件进行过滤。 示例日志消息序列:

<time> INFO Fetching data for apple.
<time> INFO Fetching data for mango.
<time> INFO Fetching data for orange.
<time> ERROR error message. 
<time> INFO Fetching data for banana.
<time> ERROR error message. 
<time> INFO Fetching data for jackfruit.
<time> INFO Fetching data for figs.

【问题讨论】:

    标签: amazon-web-services amazon-cloudwatch aws-cloudwatch-log-insights


    【解决方案1】:

    我不相信这是可能的。

    一种选择是在查询的选择部分中包含@logStream,这将允许您单击日志流链接直接转到日志项,并向上滚动以查看先前的日志。

    不适合您的情况,但可能会加快您的调试速度。

    【讨论】:

    • 使用此方法时,还要包含@timestamp 和@log。即fields @timestamp, @log, @logStream。该链接使用所有 3 个字段 - @timestamp 用于开始时间,@log 用于查询多个日志组。
    最近更新 更多