Skip to content

Commit

Permalink
Merge pull request #146 from hmcts/ignore-request-in-accesslogger
Browse files Browse the repository at this point in the history
Ignore request in accesslogger
  • Loading branch information
abidfs authored May 23, 2022
2 parents 86019f0 + 93b6c13 commit 790d627
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
9 changes: 6 additions & 3 deletions log/express.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down

0 comments on commit 790d627

Please sign in to comment.