NextNodeTemplate/backend/config/logger.js
2025-11-02 16:47:30 +03:00

41 lines
1.0 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.

// Конфигурация 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;