Pino (Logging)

main.ts

// bufferLogs: true is a feature that temporarily stores (buffers) 
// all log messages that occur during the application's bootstrap process 
// until the logger is fully configured. Here's why this is important
// prevent logging loss
const app = await NestFactory.create(AppModule, { bufferLogs: true });
// Uses dependency injection to get the logger instance (app.get(Logger))
app.useLogger(app.get(Logger));
app.module.ts
@Module({
  imports: [
   // Declare logger module in global level and customize the setting
    LoggerModule.forRoot({
      pinoHttp: pinoOptionConfig(),
    })
  ],
  providers: [
    {
      provide: APP_FILTER,
      useClass: HttpExceptionFilter,
    },
  ],
})

Last updated

Was this helpful?