-
Notifications
You must be signed in to change notification settings - Fork 100
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
[FEATURE REQUEST] expose request.log.setBindings() (or request.log in general) #1280
Comments
I couldn't find such feature of |
Hi @iamolegga - I too soon noticed it is not documented, so I added the links in an edit of my original post, here they are again: https://github.com/pinojs/pino/blob/553c66ba3e33410c203a50e5460365bdc9ec61a9/lib/proto.js#L157-L161) It is actually a feature of pino itself, then pino-http attaches a logger prop to all Requests, that is where I make most use of it. |
If you have any personal or work projects using req.log.setBindings({ hello: 123 }) |
Sorry, I still could not find a time to check it out. Do I understand correctly that exposing I mean here if it works the same way when call
|
so every request has its own logger instance attached to it That said I found a good way to access |
I believe this feature request could be open. I hope I can find time to play with it and replace |
This is something that would be very helpful. @Get('foo')
foo(@Req() req: FastifyRequest) {
req.log.setBindings({ hello: 123 });
return 'foo';
} I got this error |
It looks like this is still not in a public API. No mentions in docs |
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'sassign()
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
orreq.log.setBindings()
method, wherereq
is the current request, if any current request is present.maybe something like this:
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:
The text was updated successfully, but these errors were encountered: