我需要你的帮助。我正在使用Bunyan在我的下一个应用程序中记录消息,一切都如预期的那样正常工作,但没有任何更改,消息就开始注册,没有任何严重程度。现在,在GCP中,我们看到标记为默认的消息,没有信息--没有错误,并且检查了整个对象,我可以看到它没有严重性属性。
--这是我的配置:
// Create a Bunyan logger that streams to Cloud Logging only errors
const bunyan = require('bunyan');
const loggerError = bunyan.createLogger(
{
name: 'my-app',
streams: [
{
level: 50,
stream: process.stderr,
}
],
},
);
// Create a Bunyan logger that streams to Cloud Logging only info
const loggerInfo = bunyan.createLogger(
{
name: 'my-app',
streams: [
{
level: 30,
stream: process.stdout,
}
],
},
);和我把它用作:
loggerError.error('This is an error');但是在GCP中,该消息作为默认消息存储,而不是作为错误存储。有什么想法吗?
发布于 2022-05-23 13:07:57
在我为Bunyan添加了Google客户端库之后,它为我解决了这个问题。你可以看到谷歌云文档
const bunyan = require('bunyan');
// Imports the Google Cloud client library for Bunyan
const {LoggingBunyan} = require('@google-cloud/logging-bunyan');
// Creates a Bunyan Cloud Logging client
const loggingBunyan = new LoggingBunyan();
// Create a Bunyan logger that streams to Cloud Logging
// Logs will be written to: "projects/YOUR_PROJECT_ID/logs/bunyan_log"
const logger = bunyan.createLogger({
// The JSON payload of the log as it appears in Cloud Logging
// will contain "name": "my-service"
name: 'my-service',
streams: [
// Log to the console at 'info' and above
{stream: process.stdout, level: 'info'},
// And log to Cloud Logging, logging at 'info' and above
loggingBunyan.stream('info'),
],
});
// Writes some log entries
logger.error('warp nacelles offline');
logger.info('shields at 99%');我仍然有一些默认日志,但大多数情况下,它的严重性是正确的。
https://stackoverflow.com/questions/70667299
复制相似问题