0

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. 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.

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. Any idea?

juliomalves
  • 42,130
  • 20
  • 150
  • 146
  • You mention you didn't make any changes, are you the only person using this project? No changes within project, cluster, upgrade, deploying other resources? – PjoterS Jan 12 '22 at 08:16

1 Answers1

2

After I add the Google Cloud client library for Bunyan @google-cloud/logging-bunyan It's solve the problem for me. 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.

Betzalel
  • 21
  • 5