const winston = require('winston');
const DailyRotateFile = require('winston-daily-rotate-file');
const path = require('path');
const moment = require('moment-timezone');

const chinaZone = 'Asia/Shanghai';

const logger = winston.createLogger({
    level: 'info',
    format: winston.format.combine(
      winston.format.timestamp({
        format: () => moment.tz(chinaZone).format()
      }),
      winston.format.json()
    ),
    transports: [
      new winston.transports.Console()
      // 可以添加更多的传输，例如文件传输等
    ]
  });
  
logger.add(new DailyRotateFile({
    dirname: path.join(__dirname, 'logs'),
    filename: '%DATE%.log',
    datePattern: 'YYYY-MM-DD-HH',
    zippedArchive: false,
    maxSize: '100m',
    maxFiles: '14d'
}));

logger.add(new winston.transports.Console({
    format: winston.format.simple(),
}));

module.exports = logger;