A Logger for the Laravel HTTP Client

A Logger for the Laravel HTTP Client

HTTP Client Logger is a logger for the built-in Laravel HTTP client. Using the logger will log both the request, the response and the response time of an external HTTP request made with the Laravel HTTP Client.

📂 A logger for the Laravel HTTP Client

bilfeldt/laravel-http-client-logger

An easy yet very flexible logger for the Laravel HTTP Client.

Installation

You can install the package via composer:

composer require bilfeldt/laravel-http-client-logger

Optionally publish the config file with:

php artisan vendor:publish --provider="Bilfeldt\LaravelHttpClientLogger\LaravelHttpClientLoggerServiceProvider" --tag="laravel-http-client-logger-config"

Usage

Using the logger will log both the request, the response and the response time of an external HTTP request made with the Laravel HTTP Client.

Basic logging

Http::log()->get('https://example.com'); // uses the configured logger and filter

Conditional logging

This will log the request/response when the $condition evaluates to true.

Http::logWhen($condition)->get('https://example.com'); // uses the configured logger and filter

Logging context

It is possible to supply context for the logger using:

Http::log(['note' => 'Something to log'])->get('https://example.com');
// or
Http::logWhen($condition, ['note' => 'Something to log'])->get('https://example.com');

Providing on-demand configuration

It is possible to provide on-demand configuration which will override the package configuration specified in config/laravel-http-client-logger.php:

Http::log($context, ['example-config-key' => 'value'])->get('https://example.com');
// or
Http::logWhen($condition, $context, ['example-config-key' => 'value'])->get('https://example.com');

Specifying a logger

The default logger and filter are specified in the package configuration logger and filter respectively but can be changed at runtime using:

Http::log($context, $config, $logger, $filter)->get('https://example.com');
// or
Http::logWhen($condition, $context, $config, $logger, $filter)->get('https://example.com');

Note that the logger must implement HttpLoggerInterface while the filter must implement HttpLoggingFilterInterface.

Logging example

The default logger converts the request and response to a PSR-7 HTTP message which is then logged as strings.

Log entry example when using default logger:

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":[{"name":"bilfeldt/laravel-http-client-logger","description":"A logger for the Laravel HTTP Client","keywords":["bilfeldt","laravel-http-client-logger"],"homepage":"https://github.com/bilfeldt/laravel-http-client-logger","version":"v0.2.0","version_normalized":"0.2.0.0","license":["MIT"],"authors":[{"name":"Anders Bilfeldt","email":"[email protected]","role":"Developer"}],"source":{"type":"git","url":"https://github.com/bilfeldt/laravel-http-client-logger.git","reference":"67ea252a3d3d0c9c0e1c7daa11a3683db818ad5e"},"dist":{"type":"zip","url":"https://api.github.com/repos/bilfeldt/laravel-http-client-logger/zipball/67ea252a3d3d0c9c0e1c7daa11a3683db818ad5e","reference":"67ea252a3d3d0c9c0e1c7daa11a3683db818ad5e","shasum":""},"type":"library","time":"2021-02-17T14:28:45+00:00","autoload":{"psr-4":{"Bilfeldt\\LaravelHttpClientLogger\\":"src"}},"extra":{"laravel":{"providers":["Bilfeldt\\LaravelHttpClientLogger\\LaravelHttpClientLoggerServiceProvider"]}},"require":{"php":"^7.4|^8.0","guzzlehttp/guzzle":"^7.2","illuminate/http":"^8.0","illuminate/support":"^8.0","spatie/laravel-package-tools":"^1.1"},"require-dev":{"orchestra/testbench":"^6.0","phpunit/phpunit":"^9.3","spatie/laravel-ray":"^1.12","timacdonald/log-fake":"^1.9","vimeo/psalm":"^4.4"},"support":{"issues":"https://github.com/bilfeldt/laravel-http-client-logger/issues","source":"https://github.com/bilfeldt/laravel-http-client-logger/tree/v0.2.0"}},{"version":"0.1.0","version_normalized":"0.1.0.0","source":{"type":"git","url":"https://github.com/bilfeldt/laravel-http-client-logger.git","reference":"6bb8c8ada3959643103a75aa4e639c8dddddf2df"},"dist":{"type":"zip","url":"https://api.github.com/repos/bilfeldt/laravel-http-client-logger/zipball/6bb8c8ada3959643103a75aa4e639c8dddddf2df","reference":"6bb8c8ada3959643103a75aa4e639c8dddddf2df","shasum":""},"time":"2021-02-15T22:39:05+00:00","support":{"issues":"https://github.com/bilfeldt/laravel-http-client-logger/issues","source":"https://github.com/bilfeldt/laravel-http-client-logger/tree/0.1.0"}}]},"minified":"composer/2.0"}  

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

Download Details:

Author: bilfeldt Download Link: Download The Source Code Official Website: https://github.com/bilfeldt/laravel-http-client-logger License: The MIT License (MIT). Please see License File for more information.

laravel

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Php how to delete multiple rows through checkbox using ajax in laravel

In this article i will let you know to delete multiple rows through checkbox using ajax in laravel and before delete we will give a confirmation message.

Top Laravel Development Company India | Laravel Development Services

As a Laravel development company, we use this framework to deliver robust & scalable customized Laravel web solutions & enterprise portals to global clients. 4200+ Projects | 16+ Yrs Exp | 97% Customer Retention

Hire Laravel Developers | Laravel Development Company, Services India

Hire Laravel developers & dedicated programmers in India for custom Laravel development services on an hourly / full-time basis. 16+ years exp & 4200+ projects | Strict NDA | Contact Us Today

Laravel App Development Company in India, Hire Laravel Developers

IndianAppDevelopers, leading Laravel app development company in India, Hire Laravel app developers or programmers from India at cost effective price.

Laravel Development services india | Laravel Web Development Company - CMARIX Technolabs

CMARIX is one of the leading [Laravel web development company](https://www.cmarix.com/laravel-development.html "Laravel web development company") at this time with a rating of 4.9/5 on Clutch. This is the best place where you could probably find...