[QUESTION] How to best overwrite outOfContext
logger reference
#2221
Labels
question
Further information is requested
outOfContext
logger reference
#2221
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
The text was updated successfully, but these errors were encountered: