const winston = require('winston'); const path = require('path'); // __dirname уже доступен в CommonJS, нет нужды использовать fileURLToPath // Формат для файла (подробный JSON) const fileFormat = winston.format.combine( winston.format.timestamp(), winston.format.json() ); // Формат для консоли (краткий, с цветами) const consoleFormat = winston.format.combine( winston.format.colorize(), winston.format.timestamp({ format: 'HH:mm:ss' }), winston.format.printf(({ level, message, timestamp }) => { return `${timestamp} ${level}: ${message}`; }) ); const logger = winston.createLogger({ level: 'info', transports: [ // Логирование ошибок в отдельный файл new winston.transports.File({ filename: path.join(__dirname, '../logs/error.log'), level: 'error', format: fileFormat }), // Общий лог файл new winston.transports.File({ filename: path.join(__dirname, '../logs/combined.log'), format: fileFormat }), // Консольный вывод new winston.transports.Console({ format: consoleFormat }) ] }); module.exports = logger;