Skip to content

Commit

Permalink
feat: add a logProfile method that logs the profiled request response…
Browse files Browse the repository at this point in the history
…, time, method, response status
  • Loading branch information
teclone committed Jul 26, 2018
1 parent ec93fa2 commit f0153eb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/modules/Logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,18 @@ export default {
info(message) {
console.log('\x1b[1m\x1b[32m%s\x1b[0m', message);
},

/**
* log request response profile
*@param {http.IncomingMessage} req - the request object
*@param {RServerResponse} res - the response object
*/
logProfile(req, res) {
if (res.statusCode >= 400)
console.log('%s: %s \x1b[31m%d\x1b[0m ~%dms ~%dms\x1b[0m', req.method, req.url,
res.statusCode, res.startTime - req.startTime, Date.now() - res.startTime);
else
console.log('%s: %s \x1b[32m%d\x1b[0m ~%dms ~%dms\x1b[0m', req.method, req.url,
res.statusCode, res.startTime - req.startTime, Date.now() - res.startTime);
}
};

0 comments on commit f0153eb

Please sign in to comment.