简体   繁体   English

在 GCP 中标记为没有严重性的 Bunyan 日志消息

[英]Bunyan log messages marked without severity in GCP

I need your help.我需要你的帮助。 I'm using Bunyan to log messages in my Next app and everything was working as expected, but without any changes the messages started being registered with no severity.我正在使用 Bunyan 在我的 Next 应用程序中记录消息,一切都按预期工作,但没有任何更改,消息开始注册,没有严重性。 Now, in GCP we see the messages marked as default , no info no error and checking the whole object I can see there's no severity property.现在,在 GCP 中,我们看到标记为default的消息,没有信息没有错误,检查整个 object 我可以看到没有严重性属性。

This is the configuration I have:这是我的配置:

// 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,
            }
        ],
    },
);

And I use it as:我将其用作:

loggerError.error('This is an error');

But in GCP that message is stored as a Default message and not as an Error .但在 GCP 中,该消息存储为Default消息而不是Error Any idea?任何想法?

After I add the Google Cloud client library for Bunyan @google-cloud/logging-bunyan It's solve the problem for me.在我为 Bunyan @google-cloud/logging-bunyan 添加 Google Cloud 客户端库后,它为我解决了问题。 You can see Google cloud docs你可以看到谷歌云文档


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%');

I still have some logs that came with default but mostly it's with the right severity.我仍然有一些默认日志,但主要是具有正确的严重性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM