cls_get_log_context
Retrieve log context by fetching surrounding log entries before and after a specific log to understand full sequence when troubleshooting issues.
Instructions
获取日志上下文。根据一条日志的定位信息,查看其前后的日志记录,用于排查问题时了解完整的日志上下文。
参数说明
topic_id: 日志主题 ID(必填)
btime: 目标日志的时间(字符串),支持两种格式:
毫秒时间戳字符串(如
"1774537847429"):工具内部自动按 UTC+8 时区转换为所需格式,可直接使用 cls_search_log 返回的"时间(Time)"对应的毫秒时间戳UTC+8 时间字符串
YYYY-mm-dd HH:MM:SS.FFF(如"2026-03-25 14:25:00.000"):需确保为 UTC+8 时区
pkg_id: 目标日志的包序号(从 cls_search_log 返回的 PkgId 字段获取)
pkg_log_id: 目标日志在包内的序号(从 cls_search_log 返回的 PkgLogId 字段获取)
prev_logs: 向前获取的日志条数,默认 10,最大 100
next_logs: 向后获取的日志条数,默认 10,最大 100
使用流程
先用 cls_search_log 查找目标日志
从结果中获取 PkgId、PkgLogId,以及"时间"对应的毫秒时间戳(或自行构造 UTC+8 时间字符串)
用这些信息调用本工具获取上下文
注意事项
btime 的时间字符串必须为 UTC+8 时区
传入毫秒时间戳字符串时,工具会自动按 UTC+8 转换,无需手动处理时区
毫秒精度会影响定位准确性,建议尽量使用精确的时间值
region: 地域(可选),如 ap-guangzhou、na-ashburn,不传则使用默认地域,可通过 cls_describe_regions 查询所有可用地域
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| topic_id | Yes | ||
| btime | Yes | ||
| pkg_id | Yes | ||
| pkg_log_id | Yes | ||
| prev_logs | No | ||
| next_logs | No | ||
| region | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |