在 Emulator Suite 界面中查询日志

Firebase Local Emulator Suite 提供了丰富的界面,包括对查看模拟器日志的支持。您可以使用本页面上介绍的查询语法在 Emulator Suite UI 中过滤日志。

请注意有关此语言及其语法的以下事项:

  • 支持的操作:

    • 完全比较 (key=value)
    • 模糊文本搜索(search=value 或无键文本)
    • 使用多个 key=value 表达式(以空格或换行符分隔,例如 search=github search=com)的逻辑 AND 组合。不支持 and 关键字。
  • 任何没有显式键的查询都会被视为单个 search 字词,包括任何空格。

  • 仅显式 key=value 表达式中的值支持引号(例如 search="github")。除非值包含空格或换行符(例如 search="hello world"),否则引号是可选的。

以下是针对 Emulator Suite UI 使用日志查询语言的一些示例:

// Find info logs only.
level=info

// Find logs for the `sayHelloWorld` function.
metadata.emulator.name=functions
metadata.function.name=sayHelloWorld

// Find any log mentioning `"hello world"`.
hello world  // turns into `search="hello world"` internally

// Return any Hosting `POST` requests.
metadata.emulator.name=hosting
search=POST

关键字

Emulator Suite UI 日志查询语言支持以下关键字:

level

日志级别。

warn、info、error 之一。

要在模糊搜索中匹配的文本。

例如,search=abc 会返回包含文本 "abc" 的日志。

使用 search 关键字可组合多个模糊搜索(例如 search=github search=com),或将模糊搜索与其他关键字搜索组合(例如 metadata.emulator.name=hosting search=POST)。

metadata

有关日志条目的元数据,例如模拟器或函数名称。

metadata.emulator.name

生成日志的模拟器。

firestore、functions、database、pubsub、hosting、storage 之一。

metadata.function.name

应用代码中定义的函数名称。

user

您可以在 user 下查询从应用代码记录的所有 JSON 数据。

例如:

console.log(JSON.stringify({hello: "world"}))

您可以使用 user.hello="world"(或 user.hello=world)查询日志输出。