Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
194 views
in Technique[技术] by (71.8m points)

javascript - How to get structured logs in Firebase CLI?

I have a node script that prints logs generated by all my firebase cloud functions.

const { execSync } = require("child_process");
const cmd = "firebase functions:log";
let options = {
    encoding: 'utf8'
}
let output = execSync(cmd, options)

console.log(output)

Outputs look something like this:

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' }

The output of the script is in the form of a string. Is there any way to receive all the logs in a JSON /any other structured format or do we need to use the string parsing?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

As mentioned here, theres a lot of ways you can send the data to the logs.

Judging by your comments, I would recommend you to check the example here as it holds something like what you seem to be trying to send to the logs.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...