Skip to content
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

Fix UnhandledPromiseRejection warning when logging on an ignored path #81

Merged
merged 1 commit into from
Aug 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,11 @@ async function register (server, options) {
}

function logEvent (current, event) {
// check for null logger
if (current === nullLogger) {
return
}

var tags = event.tags
var data = event.data

Expand Down
58 changes: 58 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1067,6 +1067,64 @@ experiment('ignore response logs for paths in ignorePaths', () => {
})
})

experiment('ignore request.log logs for paths in ignorePaths', () => {
test('when path matches entry in ignorePaths, nothing should be logged', async () => {
const level = 'info'
const server = getServer()
server.route({
path: '/ignored',
method: 'GET',
handler: (req, h) => {
req.log([level], 'hello logger')
return 'hello world'
}
})

server.route({
path: '/foo',
method: 'GET',
handler: (req, h) => {
req.log([level], 'foo')
return 'foo'
}
})

let resolver
const done = new Promise((resolve, reject) => {
resolver = resolve
})
const stream = sink((data) => {
expect(data.req.url).to.endWith('/foo')
expect(data.tags).to.equal([level])
expect(data.data).to.equal('foo')
resolver()
})
const logger = require('pino')(stream)
const plugin = {
plugin: Pino,
options: {
instance: logger,
logEvents: ['request-error'],
ignorePaths: ['/ignored']
}
}

await server.register(plugin)

await server.inject({
method: 'GET',
url: '/ignored'
})

await server.inject({
method: 'GET',
url: '/foo'

})
await done
})
})

experiment('logging with logRouteTags option enabled', () => {
test('when logRouteTags is true, tags are part of the logged object', async () => {
const server = getServer()
Expand Down