为了账号安全,请及时绑定邮箱和手机立即绑定

如何将错误记录到 Firebase Cloud Functions 日志?

如何将错误记录到 Firebase Cloud Functions 日志?

翻阅古今 2023-08-18 17:01:29
我无法将有意义的错误消息记录到我的函数日志中,我想要实现的目标是让错误以“错误”日志级别出现,如下所示:实际错误日志的图像相反,我得到的是这样的:测试结果图片我正在使用以下函数来测试这一点:exports.testError = functions.https.onRequest(async (request, response) =>{    console.log('Hi');    //According to google this won't be logged as error    console.error('Error');    //But these will    console.error(new Error('error'));    console.error('Error', new Error('error'));    return response.status(500).send('Test is finished.');})第一个图像是随机错误,其目的是展示我想要实现的目标,即:将错误记录为错误。第二张图片是我的测试结果,它表明即使我遵循谷歌的指示(报告错误),它也无法按预期工作。
查看完整描述

2 回答

?
侃侃无极

TA贡献2051条经验 获得超10个赞

使用 Cloud Functions 记录器 SDK,如中所述

const functions = require("firebase-functions")
functions.logger.debug("debug level in web console and gcp")
functions.logger.log("info level in web console and gcp")
functions.logger.info("info level in web console and gcp")
functions.logger.warn("info level but no icon in web console; warn icon in gcp")
functions.logger.error("error level in web console and gcp")


查看完整回答
反对 回复 2023-08-18
?
拉莫斯之舞

TA贡献1820条经验 获得超10个赞

好吧,我发现了:我使用的是节点 12,我将其更改为节点 10,现在它按预期记录错误。



查看完整回答
反对 回复 2023-08-18
  • 2 回答
  • 0 关注
  • 88 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信