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

[QUESTION] How to best overwrite outOfContext logger reference #2221

Open
4 tasks done
matzeso opened this issue Feb 3, 2025 · 0 comments
Open
4 tasks done

[QUESTION] How to best overwrite outOfContext logger reference #2221

matzeso opened this issue Feb 3, 2025 · 0 comments
Assignees
Labels
question Further information is requested

Comments

@matzeso
Copy link

matzeso commented Feb 3, 2025

Question
Hey there, I am using this library for all of our logs in our NestJS application.
We have nestjs-pino used in a shared package which exports a NestJS idiomatic abstract Logger class used as a dependency injection token and a LoggerModule that is used to configure the logger (e.g. sets logLevel based on NestJS log levels).
Our LoggerModule then maps the NestJS log levels to pino log levels and configures pino under the hood.

One issue I have is that the library currently sets the outOfContext logger only once and does not have any possibility to overwrite it.
This makes it impossible to use the LoggerModule more than once to e.g. overwrite in specific use cases settings for the logger.
I currently solve this by importing the __resetOutOfContextForTests function and running it when initializing my module, so that new config is applied to a new logger instance. This is better than ignoring new config, but still overwrites the logger that is used in other modules.

Is there any reason that the outOfContext logger is stored outside the class instance? Wouldn't it be possible to always on PinoLogger instanstiation create a new logger instance, or am I overlooking some overhead that would be produced by this?
That way I could enable each module to have their own logger instance based on the provided params.

Please mention other relevant information such as Node.js version and Operating System.
Newest NestJS + tested on ubuntu and mac

@matzeso matzeso added the question Further information is requested label Feb 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants