'use strict';

const util = require('util');
const winston = require('winston');
const args = require('./argv');
require('winston-daily-rotate-file');

const logger = winston.createLogger({
    format: winston.format.combine(
        winston.format.timestamp(),
        winston.format.printf(info => `${info.timestamp} ${info.level}: ${util.inspect(info.message)}`),
    ),
    transports: [
        new winston.transports.Console({
            level: args.level,
            format: winston.format.combine(
                winston.format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
                winston.format.colorize(),
                winston.format.printf(info => `${info.timestamp} ${info.level}: ${info.message}`),
            ),
            timestamp: true,
        }),
        new winston.transports.DailyRotateFile({
            datePattern: 'YYYY-MM-DD',
            filename: 'log/%DATE%.log',
            level: 'silly',
        }),
    ],
});

module.exports = logger;
