CartoDB-SQL-API/lib/api/middlewares/log-req-res.js

11 lines
390 B
JavaScript
Raw Normal View History

2020-07-23 18:19:40 +08:00
'use strict';
module.exports = function logReqRes ({ logOnEvent = 'finish' } = {}) {
return function logReqResMiddleware (req, res, next) {
const { logger } = res.locals;
logger.info({ client_request: req }, 'Incoming request');
res.on(logOnEvent, () => logger.info({ server_response: res, status: res.statusCode }, 'Response sent'));
next();
};
};