// Конфигурация Winston для логирования const winston = require('winston'); const logFormat = winston.format.combine( winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), winston.format.errors({ stack: true }), winston.format.splat(), winston.format.json() ); const logger = winston.createLogger({ level: process.env.LOG_LEVEL || 'info', format: logFormat, defaultMeta: { service: 'backend' }, transports: [ // Запись ошибок в файл new winston.transports.File({ filename: 'logs/error.log', level: 'error' }), // Запись всех логов в файл new winston.transports.File({ filename: 'logs/combined.log' }), ], }); // В режиме разработки также выводить в консоль if (process.env.NODE_ENV !== 'production') { logger.add(new winston.transports.Console({ format: winston.format.combine( winston.format.colorize(), winston.format.simple() ), })); } module.exports = logger;