Created
October 25, 2018 13:25
-
-
Save renarsvilnis/741918b866bac0f375c52e89ec379abe to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
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