-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Add a WithMonologChannel attribute #1847
Conversation
This attribute is meant to be used by frameworks / integrations to choose which logger instance to inject in a class when they manage several channels, if they decide to use it. This attribute will have no effect in Monolog itself as the wiring of the logger in other classes is not managed by Monolog.
the phpstan failure is unrelated to my change. It is fixed in #1848 |
* Using it with the Monolog library only has no effect at all: wiring the logger instance into | ||
* other classes is not managed by Monolog. | ||
*/ | ||
#[\Attribute(\Attribute::TARGET_CLASS)] |
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.
Should be allow it on parameters also, and possibly properties/methods?
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.
This won't work in MonologBundle. The tag would apply to the whole service. It does not support separate tags per parameter.
If you want to inject 2 different loggers in the same class with autowiring, you will need to rely on the named aliases or #[Target]
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.
Couldn't we turn the attribute into eg a binding in the bundle?
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.
btw, that's also why I did not make the attribute repeatable.
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.
binding are not per-attribute but per service.
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.
Makes sense to me, next to AsMonologProcessor.
Yeah I guess why not have this here as well |
@Seldaek do you know when the 3.5 release will be done with this attribute included ? I'm adding support for this attribute in monolog-bundle. |
I'll try to do this soon but it might be a week or two.. Would like to go through all open stuff as it's been a while |
Ok 3.5.0 is out now https://github.com/Seldaek/monolog/releases/tag/3.5.0 |
This attribute is meant to be used by frameworks / integrations to choose which logger instance to inject in a class when they manage several channels, if they decide to use it.
This attribute will have no effect in Monolog itself as the wiring of the logger in other classes is not managed by Monolog.