import { Injectable, type LoggerService as NestLoggerService } from '@nestjs/common'; import pino, { type Logger } from 'pino'; @Injectable() export class LoggerService implements NestLoggerService { private readonly logger: Logger; constructor() { this.logger = pino({ level: process.env['LOG_LEVEL'] ?? 'info', transport: process.env['NODE_ENV'] !== 'production' ? { target: 'pino-pretty', options: { colorize: true } } : undefined, }); } log(message: string, context?: string): void { this.logger.info({ context }, message); } error(message: string, trace?: string, context?: string): void { this.logger.error({ context, trace }, message); } warn(message: string, context?: string): void { this.logger.warn({ context }, message); } debug(message: string, context?: string): void { this.logger.debug({ context }, message); } verbose(message: string, context?: string): void { this.logger.trace({ context }, message); } child(bindings: Record): Logger { return this.logger.child(bindings); } }