-
Notifications
You must be signed in to change notification settings - Fork 98
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
Ginden
wants to merge
1
commit into
iamolegga:master
Choose a base branch
from
Ginden:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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 forconstructor(private logger: PinoLogger) {}
? if yes let's add the test for thisThere was a problem hiding this comment.
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.There was a problem hiding this comment.
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:
createDecoratedLoggerProvider
functionPinoLogger
is set automaticallyexample/
, and add the comment which value will be forcontext
field by default@Ginden wdyt?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 byLogger
s (either from@nestjs/common
orsrc/Logger.ts
) ends with context beingLogger
. There is no workaround for that, because it would require changing@nestjs/common
.There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 itPinoLoggerAdapter
)?@Ginden what do you think?
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
(seepino
repo :) ) I'm willing to try to create dumb classclass PinoLoggerInjected extends PinoLogger {}
and try to inject that one to@nestjs/common
.