I want to log the response body in my logs file
I have tried morgan-body but I want to log the response in a file not the console
The following code will log the request body, so is there a way to log the response too?
morgan.token('body', function (req, res) { return JSON.stringify(req.body) });
app.use(morgan(':method :url :status :response-time ms - :res[content-length] :body - :req[content-length]', {
stream: logger.successLogStream,
skip: function (req, res) { return res.statusCode >= 400 }
}));
app.use(morgan(':method :url :status :response-time ms - :res[content-length] :body - :req[content-length]', {
stream: logger.errorLogStream,
skip: function (req, res) { return res.statusCode < 400 }
}));
For example I want to following error message to be logged
return res.status(400).send({ "message": "Campaign id is not defined" })