const winston = require('winston'); const { createLogger, format, transports } = require('winston'); const logger = winston.createLogger({ format: format.combine( format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss', }), format.printf((info) => JSON.stringify({ t: info.timestamp, l: info.level, m: info.message, s: info.splat !== undefined ? `${info.splat}` : '', }) + ',' ) ), transports: [ new winston.transports.Console(), new winston.transports.File({ filename: 'global.log' }) ] }) const errorHandler = (err, req, res, next) => { console.log("ERROR NAME", err); logger.log({ level: 'info', message: err.message }); res.status(err.statusCode || 500).json({ success: false, description: err.message || "Server Error", }) } module.exports = errorHandler