const winston = require('winston'); const path = require('path'); // Create a logger instance with specified settings const logger = winston.createLogger({ level: 'info', format: winston.format.combine( winston.format.timestamp(), winston.format.json() ), transports: [ // Log to a file for application events new winston.transports.File({ filename: path.join(__dirname, '../../logs/app.log') }), // Log to a file for error events new winston.transports.File({ filename: path.join(__dirname, '../../logs/error.log'), level: 'error' }), ], }); // If not in production, log to the console as well if (process.env.NODE_ENV !== 'production') { logger.add(new winston.transports.Console({ format: winston.format.simple(), })); } // Utility function to log errors const logError = (error) => { logger.error(error); }; // Utility function to log info messages const logInfo = (message) => { logger.info(message); }; module.exports = { logError, logInfo, };