-
Notifications
You must be signed in to change notification settings - Fork 187
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
allow to ignore routes based on req and res #64
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
var should = require('should'); | ||
var util = require('util'); | ||
var _ = require('underscore'); | ||
|
||
var mocks = require('node-mocks-http'); | ||
var winston = require('winston'); | ||
|
@@ -216,6 +217,15 @@ describe('expressWinston', function () { | |
}).should.throwError(); | ||
}); | ||
|
||
it('should throw an error if ignoreRoute option is not a function', function () { | ||
(function () { | ||
expressWinston.logger({ | ||
transports: [new MockTransport({})], | ||
ignoreRoute: 'not a function' | ||
}); | ||
}).should.throwError(); | ||
}); | ||
|
||
it('should return a middleware function with three arguments that fit (req, res, next)', function () { | ||
var middleware = expressWinston.logger({ | ||
transports: [new MockTransport({})] | ||
|
@@ -460,6 +470,45 @@ describe('expressWinston', function () { | |
result.transportInvoked.should.eql(false); | ||
}); | ||
}); | ||
|
||
describe('when invoked on a route that should be ignored (options.ignoreRoute)', function () { | ||
var result; | ||
|
||
before(function (done) { | ||
setUp({ | ||
url: '/is-not-logged' | ||
}); | ||
req.skip = true; | ||
var test = { | ||
req: req, | ||
res: res, | ||
log: {} | ||
}; | ||
|
||
function next(_req, _res, next) { | ||
res.end('{ "message": "Hi! I\'m a chunk!" }'); | ||
result = test; | ||
return done(); | ||
}; | ||
|
||
var middleware = expressWinston.logger({ | ||
transports: [new MockTransport(test)], | ||
ignoreRoute: function (req, res) { | ||
return req.skip === true && req.url.match(/^\/is-not-log/); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was to illustrate that any property added to request (by a middleware for example) can be used in ignoreRoute... I guess it is not clear. I can just keep the req.url check. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, that makes total sense. Cool. |
||
} | ||
}); | ||
|
||
middleware(req, res, next); | ||
}); | ||
|
||
it('should not invoke the transport', function () { | ||
result.transportInvoked.should.eql(false); | ||
}); | ||
|
||
it('should contain a filtered request', function () { | ||
result.log.should.be.empty; | ||
}); | ||
}); | ||
}); | ||
|
||
describe('log.msg', function () { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't we be making sure
options.ignoreRoute
is actually a function?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I will add that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done... And I squashed the commit for the same price.