import { Module } from '@nestjs/common';
import { LoggerModule } from 'nestjs-pino';

const isDev = process.env['NODE_ENV'] !== 'production';

@Module({
  imports: [
    LoggerModule.forRoot({
      pinoHttp: {
        level: process.env['LOG_LEVEL'] ?? (isDev ? 'debug' : 'info'),
        // pino-pretty in dev; raw JSON in prod (consumed by log aggregators).
        transport: isDev
          ? { target: 'pino-pretty', options: { colorize: true, singleLine: false } }
          : undefined,
        // Suppress /health probes from cluttering the log stream.
        autoLogging: {
          ignore: (req) => req.url?.includes('/health') ?? false,
        },
        serializers: {
          req: (req) => ({ method: req.method, url: req.url }),
          res: (res) => ({ statusCode: res.statusCode }),
        },
      },
    }),
  ],
})
export class AppLoggerModule {}
