summy/logger.js
Vufer 31b7e14f75 feat(logging): внедрено логирование через winston
- Добавлен модуль logger.js с настройками winston для логирования в файлы и консоль
- Заменены все console.log/warn/error в bot.js на вызовы logger.info/warn/error
- Добавлена зависимость winston в package.json
- Логи теперь структурированы, с таймстампами и цветовой подсветкой в консоли
- Улучшена читаемость и удобство отладки приложения
2025-06-27 18:58:17 +03:00

43 lines
1.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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;