41 lines
1.0 KiB
JavaScript
41 lines
1.0 KiB
JavaScript
const winston = require('winston');
|
|
const path = require('path');
|
|
|
|
// Create logs directory if it doesn't exist
|
|
const fs = require('fs');
|
|
const logsDir = path.join(__dirname, '../../logs');
|
|
if (!fs.existsSync(logsDir)) {
|
|
fs.mkdirSync(logsDir, { recursive: true });
|
|
}
|
|
|
|
const logger = winston.createLogger({
|
|
level: process.env.LOG_LEVEL || 'info',
|
|
format: winston.format.combine(
|
|
winston.format.timestamp(),
|
|
winston.format.errors({ stack: true }),
|
|
winston.format.json()
|
|
),
|
|
defaultMeta: { service: 'reason-flow' },
|
|
transports: [
|
|
new winston.transports.File({
|
|
filename: path.join(logsDir, 'error.log'),
|
|
level: 'error'
|
|
}),
|
|
new winston.transports.File({
|
|
filename: path.join(logsDir, 'combined.log')
|
|
})
|
|
]
|
|
});
|
|
|
|
// Add console transport for development
|
|
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;
|