diff --git a/log/express.js b/log/express.js index abfbaef..ccb1123 100644 --- a/log/express.js +++ b/log/express.js @@ -4,18 +4,21 @@ const onFinished = require('on-finished'); const Logger = require('./Logger') class AccessLogger { - constructor(config = { }) { + constructor(config = {}) { this.logger = config.logger || Logger.getLogger('express.access'); this.formatter = config.formatter || AccessLogger.defaultFormatter; this.userLevel = config.level || AccessLogger.defaultLevel; + this.ignoreRequests = config.ignoreRequests || []; } - static middleware(config = { }) { + static middleware(config = {}) { const accessLogger = new AccessLogger(config); return (req, res, next) => { onFinished(res, () => { - accessLogger.log(req, res); + if (!accessLogger.ignoreRequests.some(ignoreRequest => req.path.match(ignoreRequest))) { + accessLogger.log(req, res); + } }); next(); diff --git a/package.json b/package.json index e954f20..2da2612 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@hmcts/nodejs-logging", - "version": "4.0.1", + "version": "4.0.2", "description": "", "scripts": { "test": "LOG_LEVEL=OFF mocha test/unit/* --reporter spec"