[FEATURE REQUEST] Adding Additional Request Scoped Context
See original GitHub issueIs it possible to add fields to the logged JSON object after the logger is configured?
For example, I’d like to add a userId and organizationId to each log after it’s gone through my authorization guard for the duration of the request.
maybe something inside my auth guard like this.logger.addContext({ userId, orgId});
. Then all logs for that request include the additional context.
I thought about extending the injected PinoLogger class, but don’t want to include a RequestScoped injectable essentially everywhere.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:5
- Comments:7 (4 by maintainers)
Top Results From Across the Web
jax rs - Request-scoped context field injections into RESTEasy ...
An instance of SecurityContext can be injected into a class field or method parameter using the @Context annotation.
Read more >Finally some context: Request scoped state in Go 1.7 - Medium
Request to get a new (shallow copied) Request containing the new context, which you then pass into other handlers without changing the (w...
Read more >Using the Spring Web Scopes, Part 1 - Manning Publications
A request-scoped bean is an object managed by Spring, for which the framework creates a new instance for every HTTP request. The app...
Read more >Injection scopes | NestJS - A progressive Node.js framework
For a request-scoped controller, a new instance is created for each inbound request, and garbage-collected when the request has completed processing.
Read more >Chapter 5. Scopes and contexts
A CDI extension can support the conversation scope for other frameworks as well. The request and application scopes are also active:.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
From pino docs it looks like there is only one way to add more fields in logger: using child logger (maybe you know some other way?). But this requires replacement of base logger in continuation local storage. Technically looks like this could be possible. But I would prefer
addFields
orassign
instead ofaddContext
becausecontext
word is already using for another thing. I’ll convert this question to feature request 👍@gitSambhal there is single open pinned issue already, you can subscribe and wait or fork and implement