首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在GCP中标记无严重程度的Bunyan日志消息

在GCP中标记无严重程度的Bunyan日志消息
EN

Stack Overflow用户
提问于 2022-01-11 13:03:38
回答 1查看 216关注 0票数 0

我需要你的帮助。我正在使用Bunyan在我的下一个应用程序中记录消息,一切都如预期的那样正常工作,但没有任何更改,消息就开始注册,没有任何严重程度。现在,在GCP中,我们看到标记为默认的消息,没有信息--没有错误,并且检查了整个对象,我可以看到它没有严重性属性。

--这是我的配置:

代码语言:javascript
复制
// 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,
            }
        ],
    },
);

和我把它用作:

代码语言:javascript
复制
loggerError.error('This is an error');

但是在GCP中,该消息作为默认消息存储,而不是作为错误存储。有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2022-05-23 13:07:57

在我为Bunyan添加了Google客户端库之后,它为我解决了这个问题。你可以看到谷歌云文档

代码语言:javascript
复制
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%');

我仍然有一些默认日志,但大多数情况下,它的严重性是正确的。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70667299

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档