bilfeldt / laravel-http-client-logger

A logger for the Laravel HTTP Client
MIT License
144 stars 19 forks source link

Add global logging #2

Open bilfeldt opened 3 years ago

bilfeldt commented 3 years ago

Add a configuration which would enable global logging of all requests made using the Laravel Http Client (if filter returns true of cause).

Note: This require the possibility to add global middleware to Illuminate\Http\Client\Factory - PR must be submitted

onlime commented 3 years ago

Hi @bilfeldt - Thanks for your great work. I have just published my own implementation of a global Laravel HTTP Client logger: onlime/laravel-http-client-global-logger. Our packages are quite different (see FAQ: How does this package differ from bilfeldt/laravel-http-client-logger?), so I didn't want to hold back my work.

I hope you get global logging as well working in your package. Maybe also use RequestSending / ResponseReceived event listeners? Don't know if that's the smartest way.

bilfeldt commented 3 years ago

Dear @onlime

Thanks for pointing my direction to this newly introduced event ResponseReceived which was apparently introduced in Laravel v8.49.2 and clearely solves this issue as this event has access to both the request and the response.

This is just a matter of simply implementing it now 😄 I would happily accept a PR for this if you are up for that, but of cause you are welcome to publish an alternative package. Maybe consider mentioning that the two packages are not compatibile since they both register the log() method on the PendingRequest class (this uses macros while yours uses mixins).