You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
973 B
37 lines
973 B
|
|
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
|
|
|