import fs from 'fs';
import path from 'path';
import winston from 'winston';
import 'winston-daily-rotate-file';

const logDirectory = path.join(process.cwd(), 'logs');
if (!fs.existsSync(logDirectory)) fs.mkdirSync(logDirectory);

const logger = winston.createLogger({
    level: 'info',
    format: winston.format.combine(winston.format.timestamp(), winston.format.json()),
    transports: [
        new winston.transports.DailyRotateFile({
            filename: path.join(logDirectory, '%DATE%-rag.log'),
            datePattern: 'YYYY-MM-DD'
        }),
        new winston.transports.Console({
            format: winston.format.combine(winston.format.colorize(), winston.format.simple())
        })
    ]
});

export default logger;
