Skip to content

Commit

Permalink
Merge fc8aec6 into a6eebc7
Browse files Browse the repository at this point in the history
  • Loading branch information
rkt2spc committed Apr 5, 2017
2 parents a6eebc7 + fc8aec6 commit daed27d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = morgan
module.exports.compile = compile
module.exports.format = format
module.exports.token = token
module.exports.silent = false

/**
* Module dependencies.
Expand Down Expand Up @@ -101,6 +102,10 @@ function morgan (format, options) {
}

return function logger (req, res, next) {
if (module.exports.silent) {
return next()
}

// request data
req._startAt = undefined
req._startTime = undefined
Expand Down
19 changes: 19 additions & 0 deletions test/morgan.js
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,25 @@ describe('morgan()', function () {
.expect(200, done)
})
})

describe('on silent mode', function () {
before(function () {
morgan.silent = true
})
after(function () {
morgan.silent = false
})

it('should not log any output', function (done) {
var stream = createLineStream(function () {
throw new Error('should not log line')
})

request(createServer({ format: 'default', stream: stream }))
.get('/')
.expect(200, done)
})
})
})

describe('morgan.compile(format)', function () {
Expand Down

0 comments on commit daed27d

Please sign in to comment.