const winston = require('winston'); const path = require('path'); const { combine, timestamp, label, json } = winston.format; // Log rotation configuration const { createLogger, transports } = winston; const { File } = transports; const filename = (new Date()).toISOString().slice(0, 19).replace(/[-T]/g, '_'); const appLogRotate = new File({ filename: path.join(__dirname, `../logs/${filename}.log`), level: 'info', maxsize: 1000000, maxFiles: 5, tailable: true, }); // Winston logger configuration const appLogger = createLogger({ format: combine( label({ label: 'App' }), timestamp(), json() ), transports: [ new winston.transports.Console(), appLogRotate ] }); module.exports = appLogger;