-
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
base: master
Are you sure you want to change the base?
Conversation
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.
one more thing that should be done before merging is the docs for this feature
@@ -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); |
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 for constructor(private logger: PinoLogger) {}
? if yes let's add the test for this
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.
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:
- 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 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 by Logger
s (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
.
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 it PinoLoggerAdapter
)?
@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
(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
.
Added docs. |
@iamolegga Any updates? |
@iamolegga any chance of this getting merged into the main project ? |
Resolves #532