普通的console.warn()出现在具有服务器性"ERROR"的日志中. [英] Plain console.warn() shows up in logs with serverity "ERROR"

查看:43
本文介绍了普通的console.warn()出现在具有服务器性"ERROR"的日志中.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 console.warn()记录某些内容时,它似乎以严重程度为"ERROR"出现在Stackdriver日志中.Stackdriver Error Reporting不会显示这些错误,因此似乎它们不被视为错误.这样就无法过滤日志以仅向我显示错误.

When I log something with console.warn() it seems to appear in the Stackdriver logs with severity "ERROR". The Stackdriver Error Reporting does not show these errors, so it seems there they are not considered errors. This makes it impossible to filter the logs to only show me errors.

阅读Stackdriver日志记录文档我的印象是不应使用普通的JavaScript控制台功能,而应使用Bunyan.那是对的吗?我没看过我不应该去的地方.

Reading the Stackdriver logging docs I get the impression that I'm not supposed to use the plain javascript console functions but instead use Bunyan. Is that correct? I didn't read anywhere that I shouldn't.

推荐答案

此后,我从Google支持部门了解到,自节点10开始,情况发生了变化(至少对于云功能而言).节点8仍使用console.info正确记录了获取级别信息和console.warn得到级别警告,这似乎与我的经验保持一致.

I have since learned from Google support that things changed (at least for cloud functions) since Node 10. Node 8 still logged correctly with console.info getting level info and console.warn getting level warning, and that seems to align with my experience.

在最新版本的firebase函数中,有记录器库应该用于编写日志.对于非Firebase环境,您可以使用@ google-cloud/logging,这似乎基本上是相同的.然后,您可以完全控制严重性级别,并且可以记录额外的JSON有效负载作为第二个参数.

In recent versions of firebase-functions there is the logger library which you should use for writing logs. For non-firebase environments you can use @google-cloud/logging which seems essentially the same thing. You then have full control over severity level as well as the ability to log extra JSON payload as the second parameter.

换句话说,不要使用本机Javascript控制台方法.

So in other words, don't use the native Javascript console methods.

这篇关于普通的console.warn()出现在具有服务器性"ERROR"的日志中.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆