Ghost/core/server/web/parent/middleware/log-request.js
Sam Lord caea330647 Change to use @tryghost/logging
no issue

Logging is now controlled by a logginrc.js file in the root of the project - and now we can just import @tryghost/logging everywhere
2021-06-15 15:59:11 +01:00

27 lines
742 B
JavaScript

const logging = require('@tryghost/logging');
/**
* @TODO: move this middleware to ignition?
*/
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();
};