import type { LoggerOptions } from 'pino'; export const getLogLevel = (): string => { return process.env.LOG_LEVEL || (process.env.NODE_ENV === 'production' ? 'info' : 'debug'); }; export const getPinoConfig = (): LoggerOptions => { const isDevelopment = process.env.NODE_ENV !== 'production'; const baseConfig: LoggerOptions = { level: getLogLevel(), formatters: { level: (label) => { return { level: label.toUpperCase() }; }, }, timestamp: () => `,"timestamp":"${new Date(Date.now()).toISOString()}"`, redact: { paths: [ 'password', 'token', 'secret', 'api_key', 'apiKey', 'authorization', 'cookie', '*.password', '*.token', '*.secret', '*.api_key', '*.apiKey', ], censor: '[REDACTED]', }, }; if (isDevelopment) { // In development, use pretty printing for better readability return { ...baseConfig, transport: { target: 'pino-pretty', options: { colorize: true, translateTime: 'SYS:standard', ignore: 'pid,hostname', singleLine: false, messageFormat: '{msg}', }, }, }; } // In production, use JSON for structured logging return baseConfig; };