Windshaft-cartodb/lib/api/middlewares/logger.js
Daniel García Aubert 02c8e28494 Finalize request's log
2020-06-05 20:08:40 +02:00

17 lines
488 B
JavaScript

'use strict';
const uuid = require('uuid');
module.exports = function initLogger ({ logger }) {
return function initLoggerMiddleware (req, res, next) {
const id = req.get('X-Request-Id') || uuid.v4();
res.locals.logger = logger.child({ id });
res.locals.logger.info({ request: req });
res.on('finish', () => res.locals.logger.info({ response: res }));
res.on('close', () => res.locals.logger.info({ end: true }));
next();
};
};