nestjs winston customization code example
Example: nest winston
// my.service.ts
import { PinoLogger, InjectPinoLogger } from "nestjs-pino";
@Injectable()
export class MyService {
// regular injecting
constructor(private readonly logger: PinoLogger) {}
// regular injecting and set context
constructor(private readonly logger: PinoLogger) {
logger.setContext(MyService.name);
}
// inject and set context via `InjectPinoLogger`
constructor(
@InjectPinoLogger(MyService.name) private readonly logger: PinoLogger
) {}
getWorld(...params: any[]) {
this.logger.info("getWorld(%o)", params);
return "World!";
}
}