-
-
Notifications
You must be signed in to change notification settings - Fork 22
Global request logging WIP #18
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Bilfeldt\LaravelHttpClientLogger\Listeners; | ||
|
||
use GuzzleHttp\MessageFormatter; | ||
use Illuminate\Http\Client\Events\RequestSending; | ||
use Illuminate\Support\Facades\Log; | ||
use Psr\Http\Message\RequestInterface; | ||
|
||
class LogRequestSending | ||
{ | ||
/** | ||
* Handle the event. | ||
* | ||
* @param RequestSending $event | ||
* @return void | ||
*/ | ||
public function handle(RequestSending $event) | ||
{ | ||
return $event->request->withMiddleware((new LoggingMiddleware( | ||
$logger ?? app(HttpLoggerInterface::class), | ||
$filter ?? app(HttpLoggingFilterInterface::class) | ||
))->__invoke($context = [], $config = [])); | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Bilfeldt\LaravelHttpClientLogger\Listeners; | ||
|
||
use GuzzleHttp\MessageFormatter; | ||
use Illuminate\Http\Client\Events\ResponseReceived; | ||
use Illuminate\Support\Facades\Log; | ||
use Bilfeldt\LaravelHttpClientLogger\Middleware\LoggingMiddleware; | ||
|
||
class LogResponseReceived | ||
{ | ||
/** | ||
* Handle the event. | ||
* | ||
* @param ResponseReceived $event | ||
* @return void | ||
*/ | ||
public function handle(ResponseReceived $event) | ||
{ | ||
$event->response->withMiddleware((new LoggingMiddleware( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: Can we just use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. True, I can't see why note. That would make sense to resolve it rather than instantiating it again |
||
$logger ?? app(HttpLoggerInterface::class), | ||
$filter ?? app(HttpLoggingFilterInterface::class) | ||
))->__invoke($context = [], $config = [])); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
namespace Bilfeldt\LaravelHttpClientLogger\Providers; | ||
|
||
use Bilfeldt\LaravelHttpClientLogger\Listeners\LogRequestSending; | ||
use Bilfeldt\LaravelHttpClientLogger\Listeners\LogResponseReceived; | ||
use Illuminate\Foundation\Support\Providers\EventServiceProvider as BaseEventServiceProvider; | ||
use Illuminate\Http\Client\Events\RequestSending; | ||
use Illuminate\Http\Client\Events\ResponseReceived; | ||
|
||
class EventServiceProvider extends BaseEventServiceProvider | ||
{ | ||
/** | ||
* The event listener mappings for the application. | ||
* | ||
* @var array | ||
*/ | ||
protected $listen = [ | ||
RequestSending::class => [ | ||
LogRequestSending::class, | ||
], | ||
ResponseReceived::class => [ | ||
LogResponseReceived::class, | ||
], | ||
]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we test this using a simple unit test that uses
See: |
||
|
||
/** | ||
* Get the events and handlers. | ||
* | ||
* @return array | ||
*/ | ||
public function listens() | ||
{ | ||
return config('http-client-logger.global') ? $this->listen : []; | ||
kyranb marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
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.
Question: Can we just use
app(LoggingMiddleware::class)
instead?