anym0re/laravel-http-client-logger
Composer 安装命令:
composer require anym0re/laravel-http-client-logger
包简介
A logger for the Laravel HTTP Client
README 文档
README
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
Laravel
This package makes use of Laravels package auto-discovery mechanism so there is no need to do any futher steps - skip directly to the usage section below. If for some reason you wish to opt-out of package auto discovery, check the Laravel Docs for more details.
Lumen
NOTE: Lumen is not officially supported by this package. However, we are currently not aware of any incompatibilities.
If you use Lumen register the service provider in bootstrap/app.php like so:
<?php // bootstrap/app.php $app->register(Bilfeldt\LaravelHttpClientLogger\LaravelHttpClientLoggerServiceProvider::class); // If you want to use the Facades provided by the package $app->withFacades();
Config
Optionally in Laravel 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":"abilfeldt@gmail.com","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
- Anders Bilfeldt: Main package developer
- Henry Be: Cover image
License
The MIT License (MIT). Please see License File for more information.
anym0re/laravel-http-client-logger 适用场景与选型建议
anym0re/laravel-http-client-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 15 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 11 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 anym0re/laravel-http-client-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 anym0re/laravel-http-client-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 15
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 2
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-11-25
