Last active
July 25, 2019 17:52
-
-
Save JosielFaleiros/f03aa4df6de9b7655ed2512500b6e010 to your computer and use it in GitHub Desktop.
This file contains 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
const { performance } = require('perf_hooks'); | |
const app = express(); | |
const logRequestStart = (req, res, next) => { | |
var t0 = performance.now(); | |
console.info(`\n\n\n${req.method} ${req.originalUrl}\n\n`); | |
res.on('finish', () => { | |
var t1 = performance.now(); | |
// console.log("Call to doSomething took " + + " milliseconds.") | |
console.info(`\n\n\n\n [FINISH] ${req.method} ${req.originalUrl} ${res.statusCode} ${res.statusMessage}; ${res.get('Content-Length') || 0}b sent IN ${((t1 - t0) / 1000).toFixed(2)} SECONDS\n\n\n`) | |
}) | |
next() | |
} | |
app.use(logRequestStart) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment