0

im tring to create a logger for my own system. I have a problem getting the res.body, i am using morgan as a middel ware and wrote cutome tokens for getting req and res body, i can easily get the request body but not resespone body.

  morgan.token('qbody', (req) => {
    return JSON.stringify(req.body)
})

morgan.token('sbody', (res) => {

    return JSON.stringify(res.body)
})

is there is any way to get the response body?

Venkat Cpr
  • 153
  • 1
  • 11

1 Answers1

0

by using method overloading i sloved this problem

app.use(function (req, res, next) {
var json = res.json
res.json = function (obj) {
    function loging(obj) {
        console.log(obj) //res.body
        console.log(req.body)
    }
    loging(obj)

    json.call(this, obj)
}
next()
})
Venkat Cpr
  • 153
  • 1
  • 11