- 谷歌应用引擎标准
- 运行时: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()
orconsole.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()
的 INFO 或 ERROR。
希望我不必写 crazy custom transport只是为了使用普通的 console.error()
。
最佳答案
经过数小时的尝试,我成功了。 我根据文档使用了 Winston https://cloud.google.com/logging/docs/setup/nodejs#using_winston .
然后在 stackdriver 日志查看器中,我从下拉列表中选择了 winston_log
,如下所示 -
它现在显示错误日志。
这也适用于 Bunyan。您必须为 Bunyan 选择 bunyan_log
。
希望这对某人有帮助:)
关于javascript - GAE node.js console.error() 未记录为 ERROR 日志级别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54151629/