/** * src/utils/logger.ts * * Structured application logger built on Winston. * In development: coloured, human-readable output. * In production: single-line timestamped output for HF Spaces logs. */ import winston from 'winston'; const { combine, timestamp, colorize, printf, errors } = winston.format; const isDev = (process.env.NODE_ENV ?? 'production') === 'development'; const devFormat = combine( colorize({ all: true }), timestamp({ format: 'HH:mm:ss' }), errors({ stack: true }), printf(({ timestamp: ts, level, message, stack }) => stack ? `[${ts}] ${level}: ${message}\n${stack}` : `[${ts}] ${level}: ${message}` ) ); const prodFormat = combine( timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), errors({ stack: true }), printf(({ timestamp: ts, level, message, stack }) => stack ? `[${ts}] ${level.toUpperCase()}: ${message}\n${stack}` : `[${ts}] ${level.toUpperCase()}: ${message}` ) ); export const logger = winston.createLogger({ level: isDev ? 'debug' : 'info', format: isDev ? devFormat : prodFormat, transports: [new winston.transports.Console()], });