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

我无法将有意义的错误消息记录到我的函数日志中,我想要实现的目标是让错误以“错误”日志级别出现,如下所示:

实际错误日志的图像

相反,我得到的是这样的:

测试结果图片

我正在使用以下函数来测试这一点:

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.');

})

第一个图像是随机错误,其目的是展示我想要实现的目标,即:将错误记录为错误。


第二张图片是我的测试结果,它表明即使我遵循谷歌的指示(报告错误),它也无法按预期工作。


翻阅古今
浏览 91回答 2
2回答

侃侃无极

使用 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")

拉莫斯之舞

好吧,我发现了:我使用的是节点 12,我将其更改为节点 10,现在它按预期记录错误。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript