• Reading time ~ 1 min
  • 10.07.2022

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:

Http::log()->get('https://repo.packagist.org/p2/bilfeldt/laravel-http-client-logger.json');
 
//[2021-03-08 06:58:49] local.DEBUG: Time 0.12105202674866sec
//Request
//GET /p2/bilfeldt/laravel-http-client-logger.json HTTP/1.1
//User-Agent: GuzzleHttp/7
//Host: repo.packagist.org
//
//
//Response
//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
//
//{"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():

// Log some context along with the HTTP request log
Http::log(['note' => 'Something to log'])->get('https://example.com');
 
// Log (with context) when $condition === true
Http::logWhen($condition, ['note' => 'Something to log'])
    ->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.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297