nestjs-pino
nestjs-pino copied to clipboard
[FEATURE REQUEST] expose request.log.setBindings() (or request.log in general)
Is your feature request related to a problem? Please describe.
I'd like to add context to the "request completed|errored" log, with vanilla pino-http I can do this via req.log.setBindings()
. This is similar to this lib's assign()
method which creates a child logger under the hood, except the difference is that we can use it to add context to the onResponse log, allowing us to have just 1 log per request with all required context.
Describe the solution you'd like
I'd this the PinoLogger to expose req.log
or req.log.setBindings()
method, where req
is the current request, if any current request is present.
maybe something like this:
// sets bindings on current request if this code is part of handling a request
this.logger.setReqLogBindings({foo: "bar})
Describe alternatives you've considered
Threading through the request object deep into different parts of the code base and doing req.log.setBindings()
there.
Additional context
setBindings() ref:
- https://github.com/pinojs/pino/blob/553c66ba3e33410c203a50e5460365bdc9ec61a9/lib/proto.js#L157-L161)
- https://github.com/pinojs/pino/blob/013dc0667de75154553f763f781fb0d2d7146574/pino.d.ts#L116-L122