如何在 Firebase CLI 中获取结构化日志?
How to get structured logs in Firebase CLI?
我有一个节点脚本可以打印我所有的 firebase 云函数生成的日志。
const { execSync } = require("child_process");
const cmd = "firebase functions:log";
let options = {
encoding: 'utf8'
}
let output = execSync(cmd, options)
console.log(output)
输出看起来像这样:
2021-01-06T09:06:05.541212726Z D saveGarment: Function execution took 736 ms, finished with status code: 204
2021-01-06T09:06:10.844901031Z D saveGarment: Function execution started
2021-01-06T09:06:16.153Z ? saveGarment: CORE
2021-01-06T09:06:18.134508823Z D saveGarment: Function execution took 7470 ms, finished with status code: 200
2021-01-06T09:06:19.546Z ? saveGarment: { message: 'fail' }
脚本的输出是字符串的形式。有什么方法可以接收 JSON /任何其他结构化格式的所有日志,还是我们需要使用字符串解析?
我有一个节点脚本可以打印我所有的 firebase 云函数生成的日志。
const { execSync } = require("child_process");
const cmd = "firebase functions:log";
let options = {
encoding: 'utf8'
}
let output = execSync(cmd, options)
console.log(output)
输出看起来像这样:
2021-01-06T09:06:05.541212726Z D saveGarment: Function execution took 736 ms, finished with status code: 204
2021-01-06T09:06:10.844901031Z D saveGarment: Function execution started
2021-01-06T09:06:16.153Z ? saveGarment: CORE
2021-01-06T09:06:18.134508823Z D saveGarment: Function execution took 7470 ms, finished with status code: 200
2021-01-06T09:06:19.546Z ? saveGarment: { message: 'fail' }
脚本的输出是字符串的形式。有什么方法可以接收 JSON /任何其他结构化格式的所有日志,还是我们需要使用字符串解析?