From 8e0366c1ed985112fd751fb925fb2dc20cf480b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Garc=C3=ADa=20Aubert?= Date: Thu, 23 Jul 2020 12:19:40 +0200 Subject: [PATCH] Missing new middleware --- lib/api/middlewares/log-req-res.js | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 lib/api/middlewares/log-req-res.js diff --git a/lib/api/middlewares/log-req-res.js b/lib/api/middlewares/log-req-res.js new file mode 100644 index 00000000..0a3e1f65 --- /dev/null +++ b/lib/api/middlewares/log-req-res.js @@ -0,0 +1,10 @@ +'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(); + }; +};