2

I trying to understand formatting in GCP and using Bunyan and couldn't find any good solution. I created a logger in my app.

    import * as  bunyan  from 'bunyan';
    import { LoggingBunyan } from '@google-cloud/logging-bunyan';
    const loggingBunyan = new LoggingBunyan();

    export const loggerConfiguration = {
      name: 'name',
      serializers: {
        req: require('bunyan-express-serializer'),
        res: bunyan.stdSerializers.res,
        err: bunyan.stdSerializers.err,
      },
      streams: [
        { stream: process.stdout },
        loggingBunyan.stream('info'),
      ],
    };
export const loggerInstance = bunyan.createLogger(loggerConfiguration);

I want to be able to nicely log the error with an error code, payload, stack and error message. At moment I using such format:

 loggerInstance.error({
  errorType: applicationErrorTypes.GOOGLE_MAPS_API_ERROR,
  stack: JSON.stringify(error),
});

But this doesn't format my logs nice in GCP logger. Any useful hints how can I nicely format logs and make them more readable.

Liam
  • 27,717
  • 28
  • 128
  • 190
MarJano
  • 1,257
  • 2
  • 18
  • 39

0 Answers0