mp_getLogs
Fetch and filter console logs from the connected mini program. Use clear=true to reset buffer before an operation, then read to capture only the new logs.
Instructions
读取当前连接目标的小程序控制台日志,支持过滤。不同项目 / wsEndpoint 的持久化日志会隔离,不会混读或互相清空。常见用法:操作前用 clear=true 清空当前目标缓冲,操作后再读以拿到本次产生的日志。
过滤参数:
contains:子串匹配(对 message + 序列化后的 data 一起匹配,非正则)。
type:按级别过滤,枚举 log/info/warn/error/exception(exception 是未捕获异常,区别于 console.error)。
since:相对时间窗口,单位毫秒 —— 只返回过去 N ms 内的日志(不是绝对时间戳)。
limit:最多返回条数,默认 100,取最新的 N 条。
返回 {count, totalCount, logs[], filters, listenerAttached...}:count 是过滤后条数,totalCount 是当前目标缓冲区总条数(count<totalCount 说明被 limit/过滤截断)。listenerAttached=false 说明日志监听没挂上,可能漏日志,需 mp_recoverConnection。clear=true 只清空当前连接目标的缓冲。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| type | No | ||
| clear | No | ||
| limit | No | ||
| since | No | ||
| contains | No | ||
| maxBytes | No | ||
| connection | No | 可选连接覆盖(不传则用默认会话)。可用字段:mode(launch|connect)、cliPath、projectPath、wsEndpoint、timeout、port(【自动化端口】→ cli auto --auto-port,默认 9420;不是 IDE HTTP 服务端口,别把 IDE 服务端口传进来)、account、ticket、trustProject、args、cwd、autoClose、autoLaunch、launchTimeout、connectTimeout。 |