mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-21 09:52:06 +03:00
35e51e364b
no issue The only pieces of Ghost-Ignition used in Ghost were debug and logging. Both of these modules have been superceded by the Framework monorepo, and all usages of Ignition have now been removed, replaced with @tryghost/debug and @tryghost/logging.
27 lines
752 B
JavaScript
27 lines
752 B
JavaScript
const logging = require('@tryghost/logging');
|
|
|
|
/**
|
|
* @TODO: move this middleware to Framework monorepo?
|
|
*/
|
|
module.exports = function logRequest(req, res, next) {
|
|
const startTime = Date.now();
|
|
|
|
function logResponse() {
|
|
res.responseTime = (Date.now() - startTime) + 'ms';
|
|
req.userId = req.user ? (req.user.id ? req.user.id : req.user) : null;
|
|
|
|
if (req.err && req.err.statusCode !== 404) {
|
|
logging.error({req: req, res: res, err: req.err});
|
|
} else {
|
|
logging.info({req: req, res: res});
|
|
}
|
|
|
|
res.removeListener('finish', logResponse);
|
|
res.removeListener('close', logResponse);
|
|
}
|
|
|
|
res.on('finish', logResponse);
|
|
res.on('close', logResponse);
|
|
next();
|
|
};
|