承接 placetopay/guzzle-logger 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

placetopay/guzzle-logger

Composer 安装命令:

composer require placetopay/guzzle-logger

包简介

README 文档

README

Quality Gate Status

This is a middleware for guzzle that will help you automatically log every request and response using a PSR-3 logger.

The middleware is functional with version 7 of Guzzle.

Usage

Simple usage

From now on each request and response you execute using $client object will be logged. By default, the middleware logs every activity with level INFO.

use PlacetoPay\GuzzleLogger\Middleware\HttpLogMiddleware;
use GuzzleHttp\HandlerStack;

$logger = new Logger();  //A new PSR-3 Logger like Monolog
$stack = HandlerStack::create(); // will create a stack with middlewares of guzzle already pushed inside of it.
$stack->push(new HttpLogMiddleware($logger));
$client = new GuzzleHttp\Client([
    'handler' => $stack,
]);

With Sanitizer

With the LoggerWithSanitizer class you can obfuscate or sanitize sensitive data when logging.

fieldsToSanitize is a key-value array, with which you can determine the level of data to sanitize and the value with which to obfuscate the value. If you do not send a value and the value is found it will be sanitized with a default value ValueSanitizer::DEFAULT.

use PlacetoPay\GuzzleLogger\Middleware\HttpLogMiddleware;
use PlacetoPay\GuzzleLogger\LoggerWithSanitizer;
use PlacetoPay\GuzzleLogger\ValueSanitizer;
use GuzzleHttp\HandlerStack;


use GuzzleLogger\ValueSanitizer;

$fieldsToSanitize = [
            'request.body.instrument.card.cvv',
            'request.body.instrument.card.number' => ValueSanitizer::CARD_NUMBER->value,
            'request.body.instrument.card.expiration' => ValueSanitizer::DEFAULT->value,
            'response.body.instrument.card.number' => fn ($value) => preg_replace('/(\d{6})(\d{3,9})(\d{4})/', '$1····$3', (string) $value)
];

$stack = HandlerStack::create();
$logger = new LoggerWithSanitizer(new Logger(), $fieldsToSanitize)
$stack->push(new HttpLogMiddleware($logger));
$client = new GuzzleHttp\Client([
    'handler' => $stack,
]);

Using options on each request

You can set on each request options about your log.

name Type value description
statistics boolean option is true the middleware will log statistics about the HTTP call.
$client->get('/', [
    'log' => [
        'statistics' => true,
    ]
]);

Change log

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

License

The MIT License (MIT). Please see License File for more information.

placetopay/guzzle-logger 适用场景与选型建议

placetopay/guzzle-logger 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.66k 次下载、GitHub Stars 达 4, 最近一次更新时间为 2023 年 06 月 29 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 placetopay/guzzle-logger 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 placetopay/guzzle-logger 我们能提供哪些服务?
定制开发 / 二次开发

基于 placetopay/guzzle-logger 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6.66k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 4
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 4
  • Watchers: 4
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-06-29