Comparing version 6.1.0 to 6.2.0
@@ -70,2 +70,3 @@ 'use strict' | ||
const mergeHapiLogData = options.mergeHapiLogData | ||
const getChildBindings = options.getChildBindings ? options.getChildBindings : (request) => ({ req: request }) | ||
@@ -81,3 +82,6 @@ // expose logger as 'server.logger()' | ||
} | ||
request.logger = logger.child({ req: request }) | ||
const childBindings = getChildBindings(request) | ||
request.logger = logger.child(childBindings) | ||
return h.continue | ||
@@ -101,3 +105,4 @@ }) | ||
request.logger = request.logger || logger.child({ req: request }) | ||
const childBindings = getChildBindings(request) | ||
request.logger = request.logger || logger.child(childBindings) | ||
@@ -104,0 +109,0 @@ if (event.error && isEnabledLogEvent(options, 'request-error')) { |
{ | ||
"name": "hapi-pino", | ||
"version": "6.1.0", | ||
"version": "6.2.0", | ||
"description": "Hapi plugin for the Pino logger ", | ||
@@ -22,16 +22,16 @@ "main": "index.js", | ||
"@hapi/code": "^6.0.0", | ||
"@hapi/hapi": "^18.3.2", | ||
"@hapi/lab": "^20.2.2", | ||
"coveralls": "^3.0.6", | ||
"@hapi/hapi": "^18.4.0", | ||
"@hapi/lab": "^21.0.0", | ||
"coveralls": "^3.0.7", | ||
"flush-write-stream": "^2.0.0", | ||
"make-promises-safe": "^5.0.0", | ||
"make-promises-safe": "^5.1.0", | ||
"pre-commit": "^1.2.2", | ||
"split2": "^3.1.1", | ||
"standard": "^14.1.0" | ||
"standard": "^14.3.1" | ||
}, | ||
"dependencies": { | ||
"@hapi/hoek": "^8.2.2", | ||
"@hapi/hoek": "^8.3.0", | ||
"abstract-logging": "^1.0.0", | ||
"pino": "^5.13.2", | ||
"pino-pretty": "^3.2.1" | ||
"pino": "^5.13.5", | ||
"pino-pretty": "^3.2.2" | ||
}, | ||
@@ -38,0 +38,0 @@ "repository": { |
@@ -138,2 +138,3 @@ # hapi-pino [](https://travis-ci.org/pinojs/hapi-pino) [](https://coveralls.io/github/pinojs/hapi-pino?branch=master) | ||
``` | ||
- `[getChildBindings]` - Takes a function with the request as an input, and returns the object that will be passed into pinoLogger.child(). If omitted, then `{ req: request }` will be used for the child bindings, which automatically adds the request to every pino log call | ||
- `[ignorePaths]` - Takes an array of string routes and disables logging for each. Useful for health checks or any route that does not need logging. E.g `['/health']` | ||
@@ -140,0 +141,0 @@ - `[level]` - Set the minumum level that Pino should log out. See [Level](https://github.com/pinojs/pino/blob/master/docs/api.md#level). For example, `{level: 'debug'}` would configure Pino to output all `debug` or higher events. |
53
test.js
@@ -779,2 +779,55 @@ 'use strict' | ||
experiment('request.logger.child() bindings', () => { | ||
test('request.logger.child() bindings are { req: request } by default', async () => { | ||
const server = getServer() | ||
let done | ||
const finish = new Promise(function (resolve, reject) { | ||
done = resolve | ||
}) | ||
const stream = sink(data => { | ||
expect(data.req).to.not.be.undefined() | ||
expect(data.req.id).to.not.be.undefined() | ||
expect(data.custom).to.be.undefined() | ||
done() | ||
}) | ||
const plugin = { | ||
plugin: Pino, | ||
options: { | ||
stream: stream, | ||
level: 'info' | ||
} | ||
} | ||
await server.register(plugin) | ||
await server.inject('/something') | ||
await finish | ||
}) | ||
test('request.logger.child() bindings can be provided via getChildBindings(request)', async () => { | ||
const server = getServer() | ||
let done | ||
const finish = new Promise(function (resolve, reject) { | ||
done = resolve | ||
}) | ||
const stream = sink(data => { | ||
expect(data.req).to.be.undefined() | ||
expect(data.custom).to.not.be.undefined() | ||
done() | ||
}) | ||
const plugin = { | ||
plugin: Pino, | ||
options: { | ||
stream: stream, | ||
level: 'info', | ||
getChildBindings: (req) => ({ custom: true }) | ||
} | ||
} | ||
await server.register(plugin) | ||
await server.inject('/something') | ||
await finish | ||
}) | ||
}) | ||
experiment('logging with mergeHapiLogData option enabled', () => { | ||
@@ -781,0 +834,0 @@ test("log event data is merged into pino's log object", async () => { |
46453
1447
177
Updated@hapi/hoek@^8.3.0
Updatedpino@^5.13.5
Updatedpino-pretty@^3.2.2