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

[feat] Automatically provide context based on INQUIRER #533

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Ginden
Copy link

@Ginden Ginden commented Sep 2, 2021

Resolves #532

Copy link
Owner

@iamolegga iamolegga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

one more thing that should be done before merging is the docs for this feature

__tests__/utils/test-case.ts Show resolved Hide resolved
@@ -55,7 +55,7 @@ describe('no context', () => {

const ctrlLog = logs.find((v) => v.msg === msg);
expect(ctrlLog).toBeTruthy();
expect(ctrlLog).not.toHaveProperty('context');
expect(ctrlLog?.context).toEqual(TestController.name);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this work only when using InjectPinoLogger? will it work for constructor(private logger: PinoLogger) {}? if yes let's add the test for this

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It won't work. Though, adding dependency on Inquirer to PinoLogger is possible.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, let me think. In such case, we can get rid of this decorator, I believe in 95% it's called with the name of the class, so if we can add Inquirer to PinoLogger almost everyone can just drop decorator, and the rest who need to redefine context to different name will use .setContext.

So, in the current major we can add Inquirer to PinoLogger, after that deprecate the usage of @InjectPinoLogger. And drop it in the next major. This should simplify the API of this lib. So let's move this way.

So, what we need right now:

  • add inquirer to PinoLogger, add/change test to 1) check that context is set automatically and 2) can be redefined in constructor.
  • add warn log about deprecation of usage of decorator in createDecoratedLoggerProvider function
  • add docs on this feature and a note that decorator is deprecated and context for PinoLogger is set automatically
  • change usage of decorator from example/, and add the comment which value will be for context field by default

@Ginden wdyt?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like a great idea. <3

I will try to implement it when I have time.

Copy link
Author

@Ginden Ginden Oct 12, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamolegga I think this approach is infeasible, because it breaks other things.

PinoLogger instances request by Loggers (either from @nestjs/common or src/Logger.ts) ends with context being Logger. There is no workaround for that, because it would require changing @nestjs/common.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Ginden let me check this in the next couple of weeks, maybe I could find any workaround, if not let's merge this as is

Copy link

@exarus exarus Aug 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamolegga maybe we can provide different logger classes for user-injected PinoLogger and for @nestjs/common (e.g. name it PinoLoggerAdapter)?
@Ginden what do you think?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that I would like to extends codebase with one more class, this became a complex project already for just a logger.

If there is no easy way to implement this feature, maybe complex solution doesn't worth skipping one simple line of code this.logger.setContext(MyService.name)

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@iamolegga i think a good, easy to use and performant logger is a bit more complex than just a logger (see pino repo :) ) I'm willing to try to create dumb class class PinoLoggerInjected extends PinoLogger {} and try to inject that one to @nestjs/common.

@Ginden
Copy link
Author

Ginden commented Oct 12, 2021

Added docs.

@Ginden
Copy link
Author

Ginden commented Jan 15, 2022

@iamolegga Any updates?

@Soulusions
Copy link

@iamolegga any chance of this getting merged into the main project ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE REQUEST] Use @Inquirer dependency injection
4 participants