2017-11-16 15:41:33 +01:00
|
|
|
'use strict';
|
|
|
|
|
2017-12-18 15:12:44 +01:00
|
|
|
const url = require('url');
|
2017-11-16 15:41:33 +01:00
|
|
|
|
|
|
|
module.exports = function(config) {
|
2019-04-30 21:14:23 +02:00
|
|
|
const logger = config.getLogger('HTTP');
|
2017-11-16 15:41:33 +01:00
|
|
|
return (req, res, next) => {
|
|
|
|
if (config.enableRequestLogger) {
|
2020-04-30 23:04:06 +02:00
|
|
|
res.on('finish', () => {
|
|
|
|
const { pathname } = url.parse(req.originalUrl);
|
|
|
|
logger.info(`${res.statusCode} ${req.method} ${pathname}`);
|
|
|
|
});
|
2017-11-16 15:41:33 +01:00
|
|
|
}
|
2020-04-30 23:04:06 +02:00
|
|
|
next();
|
2017-11-16 15:41:33 +01:00
|
|
|
};
|
|
|
|
};
|