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

Default context per service (configurable injection scope) #610

Closed
mitsos1os opened this issue Jan 3, 2023 · 3 comments
Closed

Default context per service (configurable injection scope) #610

mitsos1os opened this issue Jan 3, 2023 · 3 comments
Labels

Comments

@mitsos1os
Copy link

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 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:

  1. 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
  2. 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!

@HmFlashy
Copy link

HmFlashy commented Feb 15, 2023

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.

@github-actions
Copy link
Contributor

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions github-actions bot added the slate label Jun 27, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Jul 5, 2023

This issue was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Jul 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants