Skip to content

Instantly share code, notes, and snippets.

@renarsvilnis
Created October 25, 2018 13:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save renarsvilnis/741918b866bac0f375c52e89ec379abe to your computer and use it in GitHub Desktop.
Save renarsvilnis/741918b866bac0f375c52e89ec379abe to your computer and use it in GitHub Desktop.
// ...
function loggingMiddleware (req, res, next) {
const id = genReqId(req)
req.log = res.log = logger.child({reqId: id})
req.log[useLevel]({req}, 'Recieved request')
res[startTime] = res[startTime] || Date.now()
if (!req.res) { req.res = res }
res.on('finish', onResFinished)
res.on('error', onResFinished)
if (next) {
next()
}
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment