javascript - GAE node.js console.error() 未记录为 ERROR 日志级别

标签 javascript node.js google-app-engine logging stackdriver

  • 谷歌应用引擎标准
  • 运行时:nodejs10

我不确定我是怎么把它搞砸的,因为它看起来很简单。根据app engine standard documentation :

console.error('message');

在 Stackdriver 日志查看器中应具有 ERROR 日志级别。但是,我看到日志级别设置为“任何日志级别”。从 logName 中可以看出,它正在记录到 stderr,这看起来是正确的。

logName:  "projects/my-project-name/logs/stderr"  

引用:

To emit a log item from your Node.js app, you can use the console.log() or console.error() functions, which have the following log levels:

  • Items emitted with console.log() have the INFO log level.
  • Items emitted with console.error() have the ERROR log level.
  • Internal system messages have the DEBUG log level.

我最初试图让 winston 与 Stackdriver 一起工作(使用 @google-cloud/logging-winston )以获得更精细的日志记录级别,但现在我什至无法让它在 处登录带有基本 console.log()console.error() 的 INFOERROR

希望我不必写 crazy custom transport只是为了使用普通的 console.error()

最佳答案

经过数小时的尝试,我成功了。 我根据文档使用了 Winston https://cloud.google.com/logging/docs/setup/nodejs#using_winston .

然后在 stackdriver 日志查看器中,我从下拉列表中选择了 winston_log,如下所示 - enter image description here

它现在显示错误日志。

这也适用于 Bunyan。您必须为 Bunyan 选择 bunyan_log

希望这对某人有帮助:)

关于javascript - GAE node.js console.error() 未记录为 ERROR 日志级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54151629/

相关文章:

javascript - Firebase signInwithRedirect() 总是转到本地主机而不是我的应用程序

javascript - 我怎样才能正确地渲染这个组件?

eclipse - 如何将项目添加为 GWT/GAE 项目的依赖项

javascript - 如何在 package.json 中指定 browserify 扩展?

javascript - Chart.js 条形图基于Label加载数据

node.js - 如何通过最新的 NVM 更改 Node 的默认版本。

node.js - Firebase 身份验证(不是函数,也不是构造函数)

node.js - 文档数据库 : Coldfusion Returning 401 Authorization error

python - Google App Engine 抛出此 InvalidURL ("nonnumeric port: ' %s'"% host[i+1 :]) exception when I try to deploy. 如何修复它?

google-app-engine - 允许在谷歌云存储上公开共享文件