nodejs-logging icon indicating copy to clipboard operation
nodejs-logging copied to clipboard

Logging a circularly dependent object does nothing.

Open drunkcod opened this issue 1 year ago • 1 comments

Environment details

  • OS: Mac OS 15
  • Node.js version: 22
  • npm version: 10.8.3
  • @google-cloud/logging version: 11.2 (via logging-winston 6.0.0)

Steps to reproduce

  1. log something having a circular reference
  2. see nothing in the logs

The below will using a plain console transport log an error. With the LoggingWinston transport on the other hand the error will be silent.

import { LoggingWinston } from "@google-cloud/logging-winston";
import winston from 'winston';

const logSomething = (transport) => {
    const logger = winston.createLogger({
        transports: [transport],
        format: winston.format.combine(
            winston.format.errors({ stack: true }),
            winston.format.json()),
    })

    logger.info('hello logging world');

    const error = { 
        message: 'hello error world',
    };
    //it's usally indirect but this will do
    error['cause'] = error;

    logger.error('here a circular problem', error);
    logger.info('bye');
}

logSomething(new winston.transports.Console());

logSomething(new LoggingWinston({
    redirectToStdout: true,
    useMessageField: false,
    projectId: process.env.gcpProjectId,
}));

This is extra problematic due to a common error AxiosError having a circular dependency and hence such failures are omitted from production logs.

drunkcod avatar Nov 04 '24 14:11 drunkcod