P Client Logger is a logger for the built-in Laravel HTTP client. It makes logging the request and response simple by sending it to a configured Laravel logger.
In its simplest form, this Logger package will output the following example log:
1Http::log()->get('https://repo.packagist.org/p2/bilfeldt/laravel-http-client-logger.json'); 2 3//[2021-03-08 06:58:49] local.DEBUG: Time 0.12105202674866sec 4//Request 5//GET /p2/bilfeldt/laravel-http-client-logger.json HTTP/1.1 6//User-Agent: GuzzleHttp/7 7//Host: repo.packagist.org 8// 9//10//Response11//HTTP/1.1 200 OK12//Server: nginx13//Date: Mon, 08 Mar 2021 06:58:49 GMT14//Content-Type: application/json15//Last-Modified: Wed, 17 Feb 2021 14:31:03 GMT16//Transfer-Encoding: chunked17//Connection: keep-alive18//Vary: Accept-Encoding19//20//{"packages":{"bilfeldt/laravel-http-client-logger":[...]}}
You can also conditionally log HTTP requests based on a given “truthy” condition using the logWhen()
and even supply logging context to both log()
and logWhen()
:
1// Log some context along with the HTTP request log2Http::log(['note' => 'Something to log'])->get('https://example.com');3 4// Log (with context) when $condition === true5Http::logWhen($condition, ['note' => 'Something to log'])6 ->get('https://example.com');
Additionally, this package allows you to pass on-demand logging configuration and even specify a logger for complete HTTP logging flexibility.
This implementation is made possible through the macroable PendingRequest
class you can see in action here.
You can learn more about this package, get full installation instructions, and view the source code on GitHub.
0 comments:
Post a Comment
Thanks