To use nestjs-pino as the primary logger for your entire NestJS application, you should register it via app.useLogger(). This allows your application code to remain implementation-agnostic by using the standard @nestjs/common Logger.
When performing this substitution, it is recommended to set bufferLogs: true in your NestFactory.create call. This forces NestJS to buffer logs until the custom logger is ready, preventing loss of early startup logs.
For standalone applications, you must manually call app.flushLogs() after the logger is ready to ensure buffered logs are emitted.
// main.ts (Standard Application)
import { Logger } from 'nestjs-pino';
const app = await NestFactory.create(AppModule, { bufferLogs: true });
app.useLogger(app.get(Logger));
// main.ts (Standalone Application)
import { Logger } from 'nestjs-pino';
const app = await NestFactory.createApplicationContext(AppModule, { bufferLogs: true });
app.useLogger(app.get(Logger));
app.flushLogs();