Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[FrameworkBundle] revert implementing LoggerAwareInterface in HTTP client decorators#54674
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
xabbuh commentedApr 19, 2024
| Q | A |
|---|---|
| Branch? | 7.1 |
| Bug fix? | no |
| New feature? | no |
| Deprecations? | no |
| Issues | |
| License | MIT |
| * @author Jérémy Derussé <jeremy@derusse.com> | ||
| */ | ||
| class RetryableHttpClientimplements HttpClientInterface,LoggerAwareInterface,ResetInterface | ||
| class RetryableHttpClientimplements HttpClientInterface, ResetInterface |
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.
Implementing theLoggerAwareInterface when the constructor already receives a logger doesn't look reasonable to me.
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 also wonder if we shouldn't change the other decorators to let them optionally receive a logger in their constructor too instead of implementing theLoggerAwareInterface
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.
doing so would also allow us to revert thecomposer.json changes
bbc39d2 to3d39484Compare| $this->logger =$logger; | ||
| if (null !==$logger &&$this->clientinstanceof LoggerAwareInterface) { | ||
| $this->client->setLogger($logger); |
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 am not convinced that a decorator should actually modify the decorated HTTP client this way. IMO setting the logger is the user's responsibility when constructing the client.
nicolas-grekas commentedApr 22, 2024
Looking at your comments here, I wonder if we should keep#54668 or not? |
yann-eugone commentedApr 22, 2024 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Sure, On that project, constructing an finalclass HttpClientFactory{publicfunction__construct(privatereadonlyHttpClientInterface$http, ) { }publicfunctioncreate(Config$config,LoggerInterface$logger):HttpClientInterface {$client =match (...) { Config::A =>$this->clientA(), Config::B =>$this->clientB(), };if ($clientinstanceof LoggerAwareInterface) {$client->setLogger($logger); }return$client; }privatefunctionclientA():HttpClientInterface {return$this->http->withOptions([ ... ]); }privatefunctionclientB():HttpClientInterface {return$this->http->withOptions([ ... ]); }} I'm using As you can see, the #[WithMonologChannel('feature1')]finalclass Feature1{publicfunction__construct(privatereadonlyHttpClientFactory$httpClientFactory,privatereadonlyLoggerInterface$logger, ) { }publicfunctionmethod(Config$config):void {$http =$this->httpClientFactory->create($config,$this->logger);... }}#[WithMonologChannel('feature2')]finalclass Feature2{publicfunction__construct(privatereadonlyHttpClientFactory$httpClientFactory,privatereadonlyLoggerInterface$logger, ) { }publicfunctionmethod(Config$config):void {$http =$this->httpClientFactory->create($config,$this->logger);... }} I've only proposed adding |
This comment was marked as outdated.
This comment was marked as outdated.
setLogger() calls for registered HTTP clients This comment was marked as outdated.
This comment was marked as outdated.
xabbuh commentedApr 24, 2024
What about supporting passing the logger to privatefunctionclientA(LoggerInterface$logger):HttpClientInterface{return$this->http->withOptions(['extra' => ['logger' =>$logger, ],// ... ]);} |
nicolas-grekas commentedApr 29, 2024
I wonder if we need this PR at all: to me, the actual http client that does log should already have the logger wired. Did you check this aspect? |
8ae7a05 to436bf31ComparesetLogger() calls for registered HTTP clientsxabbuh commentedApr 30, 2024
I agree with this reasoning. That's why I suggest to revert implementing the |
yann-eugone commentedApr 30, 2024
I don't have any opinion on this honestly |
xabbuh commentedApr 30, 2024
The actual clients do use the logger themselves. They do not use this property to configure another client. We can argue if using the interface was the right decision back when we introduced it, but that’s a different topic. |
nicolas-grekas left a comment
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.
🚀
We could even deprecate existing setLogger proxies.
fabpot commentedMay 2, 2024
Thank you@xabbuh. |
xabbuh commentedMay 2, 2024
see#54806 |
…ing clients (xabbuh)This PR was merged into the 7.1 branch.Discussion----------[HttpClient] deprecate setLogger() methods of decorating clients| Q | A| ------------- | ---| Branch? | 7.1| Bug fix? | no| New feature? | no| Deprecations? | yes| Issues |Fix#54674 (review)| License | MITCommits-------9d95152 deprecate setLogger() methods of decorating clients