Laravel HTTP Client Logger


June 3rd, 2021


HTTP 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:


//[2021-03-08 06:58:49] local.DEBUG: Time 0.12105202674866sec
//GET /p2/bilfeldt/laravel-http-client-logger.json HTTP/1.1
//User-Agent: GuzzleHttp/7
//HTTP/1.1 200 OK
//Server: nginx
//Date: Mon, 08 Mar 2021 06:58:49 GMT
//Content-Type: application/json
//Last-Modified: Wed, 17 Feb 2021 14:31:03 GMT
//Transfer-Encoding: chunked
//Connection: keep-alive
//Vary: Accept-Encoding

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():

// Log some context along with the HTTP request log
Http::log(['note' => 'Something to log'])->get('');

// Log (with context) when $condition === true
Http::logWhen($condition, ['note' => 'Something to log'])

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.

Filed in:

Paul Redmond

Full stack web developer. Author of Lumen Programming Guide and Docker for PHP Developers.