You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all, I believe that there should be unified logging across NestJS system and user's logic and services. That is why I believe the bootstrapping process on how to use the module is really important.
It is also really useful when using the logger to be able to define at every place a default context, so that it is always included in this service's logs, without you having to provide it as an extra param at every call.
Given the above, when injecting the service through @Inject(WINSTON_MODULE_NEST_PROVIDER) private logger: WinstonLogger you get the default injection scope which is a singleton for NestJS. That way, you cannot use the setContext method of the logger in the service you are injecting it into, because it will be used throughout the whole app.
There could be two approaches to tackle the problem above:
Provide a way to control the injection scope of the service and switch to TRANSIENT so that a new instance is injected everywhere and you have control over its context
Provide access to a createChild logger that will get you the child logger of the embedded Winston logger where you would be able to set a default meta object for it.
TBH, I prefer option 1 and I think some discussion was started around it in issue #122 but I see it stopped.
What do you think of the above?
Are there any suggestions to achieve what I mentioned for default context per service?
Thanks!
The text was updated successfully, but these errors were encountered:
Indeed we need multiple Logger instances, one for each NestExpressApplication with custom metadata. Right now, when using the logger in any app, it gets only the last WinstonModule that has been created with the instance associated and its metadata.
We would like to be able to create multiple WinstonModule using winston child instances, one for each app. And some utilities to be able to get the correct logger depending on the app it is used.
Hey! Thank you for your work.
First of all, I believe that there should be unified logging across NestJS system and user's logic and services. That is why I believe the bootstrapping process on how to use the module is really important.
It is also really useful when using the logger to be able to define at every place a default context, so that it is always included in this service's logs, without you having to provide it as an extra param at every call.
Given the above, when injecting the service through
@Inject(WINSTON_MODULE_NEST_PROVIDER) private logger: WinstonLogger
you get the default injection scope which is a singleton for NestJS. That way, you cannot use thesetContext
method of the logger in the service you are injecting it into, because it will be used throughout the whole app.There could be two approaches to tackle the problem above:
TRANSIENT
so that a new instance is injected everywhere and you have control over itscontext
createChild
logger that will get you the child logger of the embedded Winston logger where you would be able to set a default meta object for it.TBH, I prefer option 1 and I think some discussion was started around it in issue #122 but I see it stopped.
What do you think of the above?
Are there any suggestions to achieve what I mentioned for default context per service?
Thanks!
The text was updated successfully, but these errors were encountered: