node.jsloggingnestjstypeormpinojs

How to tell TypeORM to use different logger (pino in this case)?


I am using NestJS, TypeORM, pino and nestjs-pino.

I need pino for my logs to be in JSON format, so that Google Cloud Logging can parse the logs.

However, TypeORM logs are not in JSON format. They still somehow use their own logger.

Is it possible to tell TypeORM to use the nestjs-pino logger instead of its own?


Solution

  • I have implemented a custom TypeORM logger using pino: https://github.com/typeorm/typeorm/blob/master/docs/logging.md#using-custom-logger

    I have blatantly ripped of https://github.com/jtmthf/nestjs-pino-logger/issues/2#issuecomment-586163940 and https://github.com/typeorm/typeorm/blob/master/src/logger/SimpleConsoleLogger.ts.