probe_log
Reads the tail of a game log and filters lines by regex to verify game or mod results without consuming the file; supports repeated polling and auto UTF-8/GBK detection.
Instructions
读游戏日志尾部并按正则过滤(编码自动 utf-8/gbk)。只读、不消费,可反复轮询。
同类 Bot 项目普遍没有这条「用日志确认结果」的通道。
为什么单独做这件事:调研的 7 个游戏自动化 Bot 项目里, 没有一个用游戏日志判断结果 —— 它们靠视觉、注册表或 CDP。 而「通过日志确认结果」恰恰是最可靠的验收通道之一 (Mod 自己的输出、游戏自己的报错都在日志里),所以这里补上。
做法刻意保守:
· 只读尾部 tail_bytes(默认 256 KB)—— 日志动辄几百 MB,
绝不整个读进来;
· 给了 pattern 就只返回匹配行,并额外给 matched_count,
便于断言「没有出现 ERROR」这类否定式判据;
· 编码自动探测(utf-8 → utf-8-sig → gbk)—— 中文游戏常见 GBK。
⚠️ 它是只读的,不消费日志(不像 drain_events 那样取走即没)。
同一次读取可以反复做,所以适合轮询等待某个日志行出现。
Args: path: 日志文件路径。 pattern: 正则;只返回匹配行。留空返回尾部所有行。 max_lines: 最多返回多少行(默认 200,取最后 N 行)。 tail_bytes: 从文件末尾读多少字节(默认 262144)。
Returns: {ok, path, size, encoding, total_lines_in_tail, returned, lines: [{line_no, text}], matched_count?, has_more?, truncated_head}
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | ||
| pattern | No | ||
| max_lines | No | ||
| tail_bytes | No |